Author eryksun
Recipients Laurent.Mazuel, altendky, eryksun, georg.brandl, masthana, serhiy.storchaka
Date 2018-11-03.20:16:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.O_RDONLY)
            fcntl.ioctl(fd, EXT2_IOC_GETFLAGS, flags, True)
            flags[0] &= ~EXT2_IMMUTABLE_FL
            fcntl.ioctl(fd, EXT2_IOC_SETFLAGS, flags)

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:29eryksunsetrecipients: + eryksun, georg.brandl, Laurent.Mazuel, serhiy.storchaka, altendky, masthana
2018-11-03 20:16:29eryksunsetmessageid: <>
2018-11-03 20:16:29eryksunlinkissue26660 messages
2018-11-03 20:16:29eryksuncreate