This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <1541276189.45.0.788709270274.issue26660@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
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: <1541276189.45.0.788709270274.issue26660@psf.upfronthosting.co.za>
2018-11-03 20:16:29eryksunlinkissue26660 messages
2018-11-03 20:16:29eryksuncreate