Message329206
Serhiy, do you also plan to work around immutable files in POSIX? What about permissions on directories that prevent deleting files?
In BSD and macOS, we have os.chflags for modifying file flags. Modifying the immutable flag requires superuser access. In Linux, modifying the immutable attribute requires the CAP_LINUX_IMMUTABLE capability, and file attributes are accessed with an ioctl call. For example:
import os
import fcntl
import array
EXT2_IOC_GETFLAGS = 0x80086601
EXT2_IOC_SETFLAGS = 0x40086602
EXT2_IMMUTABLE_FL = 0x00000010
def make_mutable(filename):
flags = array.array('l', [0])
fd = os.open(filename, os.O_RDONLY)
try:
fcntl.ioctl(fd, EXT2_IOC_GETFLAGS, flags, True)
flags[0] &= ~EXT2_IMMUTABLE_FL
fcntl.ioctl(fd, EXT2_IOC_SETFLAGS, flags)
finally:
os.close(fd)
I assume for Windows this will use os.chmod. I need to rant a bit to see whether anyone else is bothered by this. Microsoft's chmod function modifies the readonly attribute as if it's a write/delete permission. I wish Python hadn't adopted this behavior, since it clashes with how chmod works on other platforms, none of which conflates native file attributes and permissions. (We can be granted permission to modify or delete an immutable file, but this doesn't enable us to modify the file until it's made mutable.) It would be nice to have os.get_file_attributes and os.set_file_attributes on Windows instead of this confused use of chmod. |
|
Date |
User |
Action |
Args |
2018-11-03 20:16:29 | eryksun | set | recipients:
+ eryksun, georg.brandl, Laurent.Mazuel, serhiy.storchaka, altendky, masthana |
2018-11-03 20:16:29 | eryksun | set | messageid: <1541276189.45.0.788709270274.issue26660@psf.upfronthosting.co.za> |
2018-11-03 20:16:29 | eryksun | link | issue26660 messages |
2018-11-03 20:16:29 | eryksun | create | |
|