Skip to content

Commit

Permalink
Merge pull request #12539 from rushabh-v/retar
Browse files Browse the repository at this point in the history
use pathlib.Path in retar.py
  • Loading branch information
Carreau committed Sep 7, 2020
2 parents cccaab9 + 90b7884 commit 6c34e4a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/retar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
import gzip
import io

from pathlib import Path

if len(sys.argv) > 2:
raise ValueError("Too many arguments")


timestamp = int(os.environ["SOURCE_DATE_EPOCH"])

path = Path(sys.argv[1])
old_buf = io.BytesIO()
with open(sys.argv[1], "rb") as f:
with open(path, "rb") as f:
old_buf.write(f.read())
old_buf.seek(0)
old = tarfile.open(fileobj=old_buf, mode="r:gz")
Expand All @@ -56,10 +59,10 @@
old.close()

buf.seek(0)
with open(sys.argv[1], "wb") as f:
with open(path, "wb") as f:
with gzip.GzipFile('', "wb", fileobj=f, mtime=timestamp) as gzf:
gzf.write(buf.read())

# checks the archive is valid.
archive = tarfile.open(sys.argv[1])
archive = tarfile.open(path)
names = archive.getnames()

0 comments on commit 6c34e4a

Please sign in to comment.