confusion with os.chmod() and follow_symlinks
David Raymond
David.Raymond at tomtom.com
Fri Feb 22 15:53:53 EST 2019
Not sure, but the way I read it follow_symlinks = True is the default behavior of systems that don't allow you to set it, and being able to set it to False is the special bit. So "allowing follow_symlinks" means it "allows you to change it to whatever you want", not "allows it to be True"
Under https://docs.python.org/3.7/library/os.html#files-and-directories it even lists the bullet point as _not_ following symlinks
-----Original Message-----
From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Karsten Hilbert
Sent: Friday, February 22, 2019 3:46 PM
To: python-list at python.org
Subject: Re: confusion with os.chmod() and follow_symlinks
On Fri, Feb 22, 2019 at 09:21:07PM +0100, 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.
Because, naively, I'd have assumed this to work:
os.chmod(directory, mode, follow_symlinks = (os.chmod in os.supports_follow_symlinks))
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list