mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
BUG FIX: use '/' as the path separator to match salt master.
On windows os.path.sep won't match the path separator used in lists of paths returned by the master. Minor optimization: calculate the probe string once ahead of the loop, not each time around.
This commit is contained in:
parent
aafe93aec4
commit
5126c7a13f
@ -140,17 +140,22 @@ class Client(object):
|
||||
'''
|
||||
ret = []
|
||||
path = self._check_proto(path)
|
||||
# We want to make sure files start with this *directory*, use
|
||||
# '/' explicitly because the master (that's generating the
|
||||
# list of files) only runs on posix
|
||||
if not path.endswith('/'):
|
||||
path = path + '/'
|
||||
|
||||
log.info(
|
||||
'Caching directory \'{0}\' for environment \'{1}\''.format(
|
||||
path, env
|
||||
)
|
||||
)
|
||||
for fn_ in self.file_list(env):
|
||||
if fn_.startswith('{0}{1}'.format(path, os.path.sep)):
|
||||
local = self.cache_file('salt://{0}'.format(fn_), env)
|
||||
if not fn_.strip():
|
||||
continue
|
||||
ret.append(local)
|
||||
#go through the list of all files finding ones that are in
|
||||
#the target directory and caching them
|
||||
ret.extend([self.cache_file('salt://' + fn_, env)
|
||||
for fn_ in self.file_list(env)
|
||||
if fn_.strip() and fn_.startswith(path)])
|
||||
|
||||
if include_empty:
|
||||
# Break up the path into a list containing the bottom-level directory
|
||||
@ -161,13 +166,13 @@ class Client(object):
|
||||
# prefix = ''
|
||||
#else:
|
||||
# prefix = separated[0]
|
||||
dest = salt.utils.path_join(
|
||||
self.opts['cachedir'],
|
||||
'files',
|
||||
env
|
||||
)
|
||||
for fn_ in self.file_list_emptydirs(env):
|
||||
if fn_.startswith('{0}{1}'.format(path, os.path.sep)):
|
||||
dest = salt.utils.path_join(
|
||||
self.opts['cachedir'],
|
||||
'files',
|
||||
env
|
||||
)
|
||||
if fn_.startswith(path):
|
||||
minion_dir = '{0}/{1}'.format(dest, fn_)
|
||||
if not os.path.isdir(minion_dir):
|
||||
os.makedirs(minion_dir)
|
||||
|
@ -1101,8 +1101,7 @@ def recurse(name,
|
||||
|
||||
if not _src_path:
|
||||
pass
|
||||
elif _src_path.strip(
|
||||
os.path.sep) not in __salt__['cp.list_master_dirs'](env):
|
||||
elif _src_path.strip('/') not in __salt__['cp.list_master_dirs'](env):
|
||||
ret['result'] = False
|
||||
ret['comment'] = (
|
||||
'The source: {0} does not exist on the master'.format(source)
|
||||
@ -1209,14 +1208,19 @@ def recurse(name,
|
||||
keep = set()
|
||||
vdir = set()
|
||||
srcpath = source[7:]
|
||||
if not srcpath.endswith('/'):
|
||||
#we're searching for things that start with this *directory*.
|
||||
# use '/' since #master only runs on posix
|
||||
srcpath = srcpath + '/'
|
||||
for fn_ in __salt__['cp.list_master'](env):
|
||||
if not fn_.strip():
|
||||
continue
|
||||
if not fn_.startswith('{0}{1}'.format(srcpath, '/')): # use '/' since
|
||||
#master only runs on posix
|
||||
if not fn_.startswith(srcpath):
|
||||
continue
|
||||
# fn_ here is the absolute source path of the file to copy from;
|
||||
# it is either a normal file or an empty dir(if include_empty==true).
|
||||
|
||||
# fn_ here is the absolute (from file_roots) source path of
|
||||
# the file to copy from; it is either a normal file or an
|
||||
# empty dir(if include_empty==true).
|
||||
|
||||
dest = os.path.join(name, os.path.relpath(fn_, srcpath))
|
||||
#- Check if it is to be excluded. Match only trailing part of the path
|
||||
@ -1239,7 +1243,7 @@ def recurse(name,
|
||||
if include_empty:
|
||||
mdirs = __salt__['cp.list_master_dirs'](env)
|
||||
for mdir in mdirs:
|
||||
if not mdir.startswith('{0}{1}'.format(srcpath, '/')): #same as above
|
||||
if not mdir.startswith(srcpath): #same as above
|
||||
continue
|
||||
mdest = os.path.join(name, os.path.relpath(mdir, srcpath))
|
||||
manage_directory(mdest)
|
||||
|
Loading…
Reference in New Issue
Block a user