use stat module instead of checksum code

- added new function for action plugins this avoids the very fragile checksum code that is shell dependant.
- ported copy module to it
- converted assemble to new stat function
- some corrections and ported temlpate
- updated old checksum function to use new stat one under the hood
- documented revamped remote checksum method
This commit is contained in:
Brian Coca 2016-02-15 17:11:49 -05:00
parent 6ddea3e915
commit b9d0662faf
4 changed files with 62 additions and 39 deletions

View file

@ -34,23 +34,18 @@ class ActionModule(ActionBase):
TRANSFERS_FILES = True
def get_checksum(self, dest, all_vars, try_directory=False, source=None):
remote_checksum = self._remote_checksum(dest, all_vars=all_vars)
try:
dest_stat = self._execute_remote_stat(dest, all_vars=all_vars, follow=False)
if remote_checksum in ('0', '2', '3', '4'):
# Note: 1 means the file is not present which is fine; template
# will create it. 3 means directory was specified instead of file
if try_directory and remote_checksum == '3' and source:
if dest_stat['exists'] and dest_stat['isdir'] and try_directory and source:
base = os.path.basename(source)
dest = os.path.join(dest, base)
remote_checksum = self.get_checksum(dest, all_vars=all_vars, try_directory=False)
if remote_checksum not in ('0', '2', '3', '4'):
return remote_checksum
dest_stat = self._execute_remote_stat(dest, all_vars=all_vars, follow=False)
result = dict(failed=True, msg="failed to checksum remote file."
" Checksum error code: %s" % remote_checksum)
return result
except Exception as e:
return dict(failed=True, msg=to_bytes(e))
return remote_checksum
return dest_stat['checksum']
def run(self, tmp=None, task_vars=None):
''' handler for template operations '''