Skip to content

Commit

Permalink
Fix tarballs so they have an entry for the root
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Nov 27, 2020
1 parent 36db789 commit e69d256
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ def flatten(image, output):
layers = [tarfile.open(fileobj=image.extractfile(layer)) for layer in manifest['Layers']]
for layer in layers:
for info in layer.getmembers():
info.name = './' + info.name
dirname, sep, basename = info.name.rpartition('/')
if basename.startswith(WHITEOUT):
del entries[dirname+sep+basename[len(WHITEOUT):]]
else:
entries[info.name] = layer, info
# need a root entry
if './' not in entries:
info = tarfile.TarInfo('./')
info.type = tarfile.DIRTYPE
info.mode = 0o755
entries[info.name] = None, info
for layer, info in entries.values():
fileobj = layer.extractfile(info) if info.isfile() else None
output.addfile(info, fileobj)
Expand Down

0 comments on commit e69d256

Please sign in to comment.