diff options
author | chima <chimaataman@gmail.com> | 2021-08-12 13:34:51 +0100 |
---|---|---|
committer | chima <chimaataman@gmail.com> | 2021-08-12 13:34:51 +0100 |
commit | c7c217901d7a68d695b074d9759a272b886e8da1 (patch) | |
tree | af0b0e83a6991e298915c27693ddc2f2a18a64f0 /src | |
parent | b4581b47748adb982a05f88897c3f3205094eb76 (diff) | |
download | click-c7c217901d7a68d695b074d9759a272b886e8da1.tar.gz |
strip win32 path prefixes from resolved absolute symlinks
Diffstat (limited to 'src')
-rw-r--r-- | src/click/types.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/click/types.py b/src/click/types.py index cd39469..d02caa2 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -845,11 +845,19 @@ class Path(ParamType): if os.path.islink(rv): rv = os.readlink(rv) - # Join dir_ with the resolved symlink. If the resolved - # path is relative, this will make it relative to the - # original containing directory. If it is absolute, this - # has no effect. - rv = os.path.join(dir_, rv) + # absolute links + if os.path.isabs(rv): + # os.readlink prepends path prefixes to absolute links + # in windows. + # Here we strip prefix from the resolved path + rv_drive, rv_path = os.path.splitdrive(rv) + stripped_rv_drive = rv_drive.split(os.path.sep)[-1] + rv = os.path.join(stripped_rv_drive, rv_path) + else: + # For relative symlinks we join dir_ to the resolved + # symlink. This will make it relative to the original + # containing directory. + rv = os.path.join(dir_, rv) try: st = os.stat(rv) |