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.

classification
Title: bug in islink() and is_symlink()
Type: enhancement Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: karaV, r.david.murray
Priority: normal Keywords:

Created on 2017-08-24 13:23 by karaV, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg300782 - (view) Author: Karine (karaV) Date: 2017-08-24 13:23
Hi,

I found a problem which can be a bug and want to inform you.

it seems os.islink() and PATH(mypath).is_symlink()  functions doen't work correct when there is linked folder inside the path:

For example I have the following path:
a/b/c/test.txt

if my c folder is link these 2 functions will not show that this path is link

Only if i remove test.txt and use a/b/c path is shows that path is link.


Seems these functions checks only last part of given path not full path and doesn't find if there is link in somewere inside path and shows not correct result.

Interesting to know your opinion regarding it.
msg300784 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-24 13:37
The docs say, eg: "Return True if the path points to a symbolic link".  The path points to a file system object, and it is the object that is being checked, not each component of the path used to get to that object.
msg300785 - (view) Author: Karine (karaV) Date: 2017-08-24 14:08
Hi David

Thanks for support. one question. I couldn't find a function which will check full path is link or not. Is there any known function>

>Четверг, 24 августа 2017, 17:38 +04:00 от "R. David Murray" <report@bugs.python.org>:
>
>
>R. David Murray added the comment:
>
>The docs say, eg: "Return True if the path points to a symbolic link".  The path points to a file system object, and it is the object that is being checked, not each component of the path used to get to that object.
>
>----------
>nosy: +r.david.murray
>resolution:  -> not a bug
>stage:  -> resolved
>status: open -> closed
>
>_______________________________________
>Python tracker < report@bugs.python.org >
>< http://bugs.python.org/issue31269 >
>_______________________________________
msg300786 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-24 14:42
I would phrase that as "check if any of the components of the path are links", at which point one "obvious"[*] answer is "any(x.is_symlink() for x in [*mypath.parents, mypath])".  If the path is absolute, you could use "not (mypath.resolve() == mypath)".

[*] I put that in quotes because it is only obvious once you have a non-trivial amount of experience with programming in Python.
msg300828 - (view) Author: Karine (karaV) Date: 2017-08-25 06:39
Thanks a lot David

>Четверг, 24 августа 2017, 18:42 +04:00 от "R. David Murray" <report@bugs.python.org>:
>
>
>R. David Murray added the comment:
>
>I would phrase that as "check if any of the components of the path are links", at which point one "obvious"[*] answer is "any(x.is_symlink() for x in [*mypath.parents, mypath])".  If the path is absolute, you could use "not (mypath.resolve() == mypath)".
>
>[*] I put that in quotes because it is only obvious once you have a non-trivial amount of experience with programming in Python.
>
>----------
>
>_______________________________________
>Python tracker < report@bugs.python.org >
>< http://bugs.python.org/issue31269 >
>_______________________________________
History
Date User Action Args
2022-04-11 14:58:51adminsetgithub: 75452
2017-08-25 06:39:09karaVsetmessages: + msg300828
2017-08-24 14:42:23r.david.murraysetmessages: + msg300786
2017-08-24 14:08:53karaVsetmessages: + msg300785
2017-08-24 13:37:57r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg300784

resolution: not a bug
stage: resolved
2017-08-24 13:27:58karaVsettitle: bug in islink() and is_simlink() -> bug in islink() and is_symlink()
2017-08-24 13:23:52karaVcreate