diff options
author | Ben Doherty <ben@thinkoomph.com> | 2016-06-01 08:29:28 -0400 |
---|---|---|
committer | Ben Doherty <ben@thinkoomph.com> | 2016-06-01 08:29:28 -0400 |
commit | ddfd32774bf54500317a7ac86ecc867390b9f84e (patch) | |
tree | d5f9d8f4b68fa78f49593cc2a9883e42e1574f7a /files | |
parent | b9971f131a3ab6dae5d860d2e99e7b7336b8c077 (diff) | |
download | ansible-modules-extras-ddfd32774bf54500317a7ac86ecc867390b9f84e.tar.gz |
Don't try to walk over files when building archive
Diffstat (limited to 'files')
-rw-r--r-- | files/archive.py | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/files/archive.py b/files/archive.py index a80fdf2a..756fea4a 100644 --- a/files/archive.py +++ b/files/archive.py @@ -230,40 +230,49 @@ def main(): arcfile = tarfile.open(dest, 'w|' + compression) for path in archive_paths: - basename = '' - - # Prefix trees in the archive with their basename, unless specifically prevented with '.' - if os.path.isdir(path) and not path.endswith(os.sep + '.'): - basename = os.path.basename(path) + os.sep - - for dirpath, dirnames, filenames in os.walk(path, topdown=True): - for dirname in dirnames: - fullpath = dirpath + os.sep + dirname - - try: - if compression == 'zip': - arcfile.write(fullpath, basename + dirname) - else: - arcfile.add(fullpath, basename + dirname, recursive=False) + if os.path.isdir(path): + basename = '' - except Exception: - e = get_exception() - errors.append('%s: %s' % (fullpath, str(e))) + # 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 - for filename in filenames: - fullpath = dirpath + os.sep + filename + # Recurse into directories + for dirpath, dirnames, filenames in os.walk(path, topdown=True): + for dirname in dirnames: + fullpath = dirpath + os.sep + dirname - if not filecmp.cmp(fullpath, dest): try: if compression == 'zip': - arcfile.write(fullpath, basename + filename) + arcfile.write(fullpath, basename + dirname) else: - arcfile.add(fullpath, basename + filename, recursive=False) + arcfile.add(fullpath, basename + dirname, recursive=False) - successes.append(fullpath) except Exception: e = get_exception() - errors.append('Adding %s: %s' % (path, str(e))) + errors.append('%s: %s' % (fullpath, str(e))) + + for filename in filenames: + fullpath = dirpath + os.sep + filename + + if not filecmp.cmp(fullpath, dest): + try: + if compression == 'zip': + arcfile.write(fullpath, basename + filename) + else: + arcfile.add(fullpath, basename + filename, recursive=False) + + successes.append(fullpath) + except Exception: + e = get_exception() + errors.append('Adding %s: %s' % (path, str(e))) + else: + if compression == 'zip': + arcfile.write(path, path[len(arcroot):]) + else: + arcfile.add(path, path[len(arcroot):], recursive=False) + + successes.append(path) except Exception: e = get_exception() |