-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The io.open
function should not consider file permissions when opening from an existing file descriptor
#967
Comments
Thanks - I really appreciate your thoroughly investigated issues! It is very helpful to have reproducible tests and good explanations. |
This one is indeed a bit tricky (the second part), so I may put it back and go for the other issues first, that seem to be more straightforward. Not today, though... |
This should be fixed in main now, though I'm sure there are still inconsistencies - the logic here is not really straightforward. At least your tests should now pass... |
Describe the bug
The low-level
os.open
function supports creating writable file handles to newly created read-only files. The returned file descriptor is valid for writing to the file, andio.open
allows creating a writer for that file handle. Whenpyfakefs
handlesio.open
, it checks the permissions on the underlying file object, which the built-inopen
does not.How To Reproduce
The following test cases will demonstrate the issue:
Bonus:
open
Mode MismatchingWhile the above issue is "simple", it does beg the question of when should the mode on a file descriptor be checked against the mode of the file object created by
open()
? In the case of built-inopen
, the answer appears to be "never", and instead thefile.flush()
can raise anEBADF
OSError
originating from thewrite()
syscall. The following demonstrates the different behavior:File handle mode mismatch tests
These situations may be more difficult to handle, as it depends on buffering behavior and the timing of the underlying syscalls that can fail. I only tested the above on my Linux system. I suspect that macOS will behave similarly, but I'm unsure about Windows.
Your environment
Please run the following in the environment where the problem happened and
paste the output.
The text was updated successfully, but these errors were encountered: