mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #39351 from ninja-/reduce_fileclient_latency
Reduce fileclient latency by merging _file_hash and _find_file
This commit is contained in:
commit
370b3409ad
@ -1277,10 +1277,10 @@ class RemoteClient(Client):
|
||||
hash_type = self.opts.get('hash_type', 'md5')
|
||||
ret['hsum'] = salt.utils.get_hash(path, form=hash_type)
|
||||
ret['hash_type'] = hash_type
|
||||
return ret
|
||||
return ret, list(os.stat(path))
|
||||
load = {'path': path,
|
||||
'saltenv': saltenv,
|
||||
'cmd': '_file_hash'}
|
||||
'cmd': '_file_hash_and_stat'}
|
||||
return self.channel.send(load)
|
||||
|
||||
def hash_file(self, path, saltenv='base'):
|
||||
@ -1289,33 +1289,14 @@ class RemoteClient(Client):
|
||||
master file server prepend the path with salt://<file on server>
|
||||
otherwise, prepend the file with / for a local file.
|
||||
'''
|
||||
return self.__hash_and_stat_file(path, saltenv)
|
||||
return self.__hash_and_stat_file(path, saltenv)[0]
|
||||
|
||||
def hash_and_stat_file(self, path, saltenv='base'):
|
||||
'''
|
||||
The same as hash_file, but also return the file's mode, or None if no
|
||||
mode data is present.
|
||||
'''
|
||||
hash_result = self.hash_file(path, saltenv)
|
||||
try:
|
||||
path = self._check_proto(path)
|
||||
except MinionError as err:
|
||||
if not os.path.isfile(path):
|
||||
return hash_result, None
|
||||
else:
|
||||
try:
|
||||
return hash_result, list(os.stat(path))
|
||||
except Exception:
|
||||
return hash_result, None
|
||||
load = {'path': path,
|
||||
'saltenv': saltenv,
|
||||
'cmd': '_file_find'}
|
||||
fnd = self.channel.send(load)
|
||||
try:
|
||||
stat_result = fnd.get('stat')
|
||||
except AttributeError:
|
||||
stat_result = None
|
||||
return hash_result, stat_result
|
||||
return self.__hash_and_stat_file(path, saltenv)
|
||||
|
||||
def list_env(self, saltenv='base'):
|
||||
'''
|
||||
|
@ -971,6 +971,7 @@ class AESFuncs(object):
|
||||
self._serve_file = self.fs_.serve_file
|
||||
self._file_find = self.fs_._find_file
|
||||
self._file_hash = self.fs_.file_hash
|
||||
self._file_hash_and_stat = self.fs_.file_hash_and_stat
|
||||
self._file_list = self.fs_.file_list
|
||||
self._file_list_emptydirs = self.fs_.file_list_emptydirs
|
||||
self._dir_list = self.fs_.dir_list
|
||||
|
Loading…
Reference in New Issue
Block a user