Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pathlib.Path in retar.py #12539

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()