mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43801 from terminalmage/issue43553
Properly handle UNC paths in salt.utils.path.readlink()
This commit is contained in:
commit
c6fd2cd452
2 changed files with 16 additions and 0 deletions
|
@ -367,6 +367,16 @@ def _file_lists(load, form):
|
|||
'roots: %s symlink destination is %s',
|
||||
abs_path, link_dest
|
||||
)
|
||||
if salt.utils.is_windows() \
|
||||
and link_dest.startswith('\\\\'):
|
||||
# Symlink points to a network path. Since you can't
|
||||
# join UNC and non-UNC paths, just assume the original
|
||||
# path.
|
||||
log.trace(
|
||||
'roots: %s is a UNCH path, using %s instead',
|
||||
link_dest, abs_path
|
||||
)
|
||||
link_dest = abs_path
|
||||
if link_dest.startswith('..'):
|
||||
joined = os.path.join(abs_path, link_dest)
|
||||
else:
|
||||
|
|
|
@ -9,6 +9,7 @@ from __future__ import absolute_import
|
|||
import errno
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -110,6 +111,11 @@ def readlink(path):
|
|||
# comes out in 8.3 form; convert it to LFN to make it look nicer
|
||||
target = win32file.GetLongPathName(target)
|
||||
except pywinerror as exc:
|
||||
# If target is on a UNC share, the decoded target will be in the format
|
||||
# "UNC\hostanme\sharename\additional\subdirs\under\share". So, in
|
||||
# these cases, return the target path in the proper UNC path format.
|
||||
if target.startswith('UNC\\'):
|
||||
return re.sub(r'^UNC\\+', r'\\\\', target)
|
||||
# if file is not found (i.e. bad symlink), return it anyway like on *nix
|
||||
if exc.winerror == 2:
|
||||
return target
|
||||
|
|
Loading…
Add table
Reference in a new issue