From e1841bb47e4f0b6ae49b87f03b99422a1df953bf Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Mon, 7 Apr 2014 20:56:46 +0200 Subject: [PATCH] fix empty leading slash entry, for real this also preserves empty directories in tar files --- bob/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bob/utils.py b/bob/utils.py index ea78c49..7cb641e 100644 --- a/bob/utils.py +++ b/bob/utils.py @@ -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."""