Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
fix empty leading slash entry, for real
Browse files Browse the repository at this point in the history
this also preserves empty directories in tar files
  • Loading branch information
dzuelke committed Apr 7, 2014
1 parent b1439fd commit e1841bb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bob/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def pipe(a, b, indent=True):
def archive_tree(dir, archive):
"""Creates a tar.gz archive from a given directory."""
with tarfile.open(archive, 'w:gz') as tar:
tar.add(dir, arcname=os.path.basename(dir))
# do not tar.add(dir) with empty arcname, that will create a "/" entry and tar will complain when extracting
for item in os.listdir(dir):
tar.add(dir+"/"+item, arcname=item)

def extract_tree(archive, dir):
"""Extract tar.gz archive to a given directory."""
Expand Down

0 comments on commit e1841bb

Please sign in to comment.