From 51ab6cdc0dddc70660f4500ca01d42871338bdbc Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Wed, 1 Jun 2016 08:59:28 -0400 Subject: [PATCH] Refactor computation of archive filenames, clearer archive filename --- lib/ansible/modules/extras/files/archive.py | 23 ++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/ansible/modules/extras/files/archive.py b/lib/ansible/modules/extras/files/archive.py index 756fea4a3e1..26394b03ad2 100644 --- a/lib/ansible/modules/extras/files/archive.py +++ b/lib/ansible/modules/extras/files/archive.py @@ -231,36 +231,35 @@ def main(): for path in archive_paths: if os.path.isdir(path): - basename = '' - - # Prefix trees in the archive with their basename, unless specifically prevented with '.' - if not path.endswith(os.sep + '.'): - basename = os.path.basename(path) + os.sep - # Recurse into directories for dirpath, dirnames, filenames in os.walk(path, topdown=True): + if not dirpath.endswith(os.sep): + dirpath += os.sep + for dirname in dirnames: - fullpath = dirpath + os.sep + dirname + fullpath = dirpath + dirname + arcname = fullpath[len(arcroot):] try: if compression == 'zip': - arcfile.write(fullpath, basename + dirname) + arcfile.write(fullpath, arcname) else: - arcfile.add(fullpath, basename + dirname, recursive=False) + arcfile.add(fullpath, arcname, recursive=False) except Exception: e = get_exception() errors.append('%s: %s' % (fullpath, str(e))) for filename in filenames: - fullpath = dirpath + os.sep + filename + fullpath = dirpath + filename + arcname = fullpath[len(arcroot):] if not filecmp.cmp(fullpath, dest): try: if compression == 'zip': - arcfile.write(fullpath, basename + filename) + arcfile.write(fullpath, arcname) else: - arcfile.add(fullpath, basename + filename, recursive=False) + arcfile.add(fullpath, arcname, recursive=False) successes.append(fullpath) except Exception: