Merge pull request #13125 from UtahDave/sanitize_strings2

Replace illegal Windows filename chars from cached file paths
This commit is contained in:
Thomas S Hatch 2014-05-30 11:10:47 -06:00
commit c7cea970dd
2 changed files with 20 additions and 1 deletions

View File

@ -515,11 +515,15 @@ class Client(object):
else:
return ''
else:
if salt.utils.is_windows():
netloc = salt.utils.sanitize_win_path_string(url_data.netloc)
else:
netloc = url_data.netloc
dest = salt.utils.path_join(
self.opts['cachedir'],
'extrn_files',
saltenv,
url_data.netloc,
netloc,
url_data.path
)
destdir = os.path.dirname(dest)

View File

@ -33,6 +33,7 @@ import types
import warnings
import yaml
from calendar import month_abbr as months
from string import maketrans
# Try to load pwd, fallback to getpass if unsuccessful
try:
@ -1288,6 +1289,20 @@ def is_windows():
return sys.platform.startswith('win')
def sanitize_win_path_string(winpath):
'''
Remove illegal path characters for windows
'''
intab = '<>:|?*'
outtab = '_' * len(intab)
trantab = maketrans(intab, outtab)
if isinstance(winpath, str):
winpath = winpath.translate(trantab)
elif isinstance(winpath, unicode):
winpath = winpath.translate(dict((ord(c), u'_') for c in intab))
return winpath
@real_memoize
def is_linux():
'''