Eryk Sun <eryk...@gmail.com> added the comment:
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. ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue26660> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com