pyfilesystem
pyfilesystem copied to clipboard
O_CREAT should be handled in fs.base.flags_to_mode
I discovered a bug when mounting an OSFS exposed over FUSE (on /mnt). A 'touch
/mnt/foo' triggers this syscall:
open("/mnt/foo", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = -1 ENOENT (No
such file or directory)
OSFS.open will be called with a mode 'r+' and it returns ENOENT (as it should).
The mode should be 'w' though, not 'r+'. This is because O_CREAT is not handled
in fs.base.flags_to_mode.
I fixed it by replacing in fs.base.flags_to_mode:
if flags & os.O_TRUNC
with:
if flags & os.O_TRUNC or flags & os.O_CREAT:
(both occurrences). It fixes the bug, although I'm not entirely sure this is
always correct.
Original issue reported on code.google.com by [email protected] on 9 Dec 2012 at 5:46
O_CREAT|O_RDONLY is not handled properly either, but I don't think there's a
way to map this to a correct mode. I ended up writing a wrapper to os.open,
which solves the issue in my case (FUSE).
Original comment by [email protected] on 23 Dec 2012 at 3:16