osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

confusion with os.chmod() and follow_symlinks


Karsten Hilbert wrote:

> Am I confused ?
> 
> ncq at hermes:~$ python3
> Python 3.7.2+ (default, Feb  2 2019, 14:31:48)
> [GCC 8.2.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os
> >>> print(os.supports_follow_symlinks)
> {<built-in function utime>, <built-in function chown>, <built-in function
> access>, <built-in function stat>, <built-in function link>} >>> os.chmod
> in os.supports_follow_symlinks False
> >>> os.chmod('/tmp/test', 0o0700, follow_symlinks = False)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NotImplementedError: chmod: follow_symlinks unavailable on this platform
> >>>
> 
> I would only have expected this exception when I actually
> request the unavailable functionality, like so:
> 
> os.chmod('/tmp/test', 0o0700, follow_symlinks = True)
> 
> This, however, works:
> 
> os.chmod('/tmp/test', 0o0700)
> 
> DESPITE the documentation saying
> 
> os.chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
> 
> IOW, the default for <follow_symlinks> being "True", which is
> certainly illogical to succeed when it is not even supported
> on this platform.
> 
> Where is my reasoning going astray ?

The special feature is to change permissions of the symlink proper rather 
than those of its target.

I think an inverted flag would indeed be clearer, e. g.

os.chmod(..., modify_symlink=False)  # instead of follow_symlinks=True

os.chmod(..., modify_symlink=True)  # instead of follow_symlinks=False; 
                                    # may raise NotImplementedError