Skip to content

Commit

Permalink
Sort planemo shed_upload tar-ball by filename.
Browse files Browse the repository at this point in the history
See GitHub issue galaxyproject#159.

Note this does not explicitly handle directories, thus any empty
directory would be missing from the tar-ball.
  • Loading branch information
peterjc committed Apr 30, 2015
1 parent a7f1b70 commit 1d09917
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions planemo/shed.py
Expand Up @@ -397,18 +397,21 @@ def build_tarball(realized_path, **kwds):
# It should be pushed up a level into the thing that is uploading tar
# balls to iterate over them - but placing it here for now because
# it address some bugs.

# Simplest solution to sorting the files is to use a list,
files = []
for dirpath, dirnames, filenames in os.walk(realized_path):
for f in filenames:
files.append(os.path.join(dirpath, f))
files.sort()

fd, temp_path = mkstemp()
try:
tar = tarfile.open(temp_path, "w:gz", dereference=True)
try:
# File system order essentially random, so at least sort
# top level entries by name:
for name in sorted(os.listdir(realized_path)):
tar.add(
os.path.join(realized_path, name),
arcname=name,
recursive=True,
)
for raw in files:
name = os.path.relpath(raw, realized_path)
tar.add(os.path.join(realized_path, name), arcname=name)
finally:
tar.close()
finally:
Expand Down

0 comments on commit 1d09917

Please sign in to comment.