diff --git a/lib/ansible/modules/extras/files/archive.py b/lib/ansible/modules/extras/files/archive.py index 2b927e39c19..3b11d86b339 100644 --- a/lib/ansible/modules/extras/files/archive.py +++ b/lib/ansible/modules/extras/files/archive.py @@ -245,6 +245,7 @@ def main(): elif format == 'tar': arcfile = tarfile.open(dest, 'w') + match_root = re.compile('^%s' % re.escape(arcroot)) for path in archive_paths: if os.path.isdir(path): # Recurse into directories @@ -254,7 +255,7 @@ def main(): for dirname in dirnames: fullpath = dirpath + dirname - arcname = fullpath[len(arcroot):] + arcname = match_root.sub('', fullpath) try: if format == 'zip': @@ -268,7 +269,7 @@ def main(): for filename in filenames: fullpath = dirpath + filename - arcname = fullpath[len(arcroot):] + arcname = match_root.sub('', fullpath) if not filecmp.cmp(fullpath, dest): try: @@ -283,9 +284,9 @@ def main(): errors.append('Adding %s: %s' % (path, str(e))) else: if format == 'zip': - arcfile.write(path, path[len(arcroot):]) + arcfile.write(path, match_root.sub('', path)) else: - arcfile.add(path, path[len(arcroot):], recursive=False) + arcfile.add(path, match_root.sub('', path), recursive=False) successes.append(path)