aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2020-05-30 23:38:58 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2020-05-30 23:38:58 -0700
commitdacd3b42154210e1d50fbe947a9bf9a7136d3081 (patch)
treeb08e0ffb3822ebc507aad692d71490ddda2ed722
parentgenrdeps: Build a .tar.xz for local use (diff)
downloadqa-scripts-dacd3b42154210e1d50fbe947a9bf9a7136d3081.tar.gz
qa-scripts-dacd3b42154210e1d50fbe947a9bf9a7136d3081.tar.bz2
qa-scripts-dacd3b42154210e1d50fbe947a9bf9a7136d3081.zip
genrdeps-index: safely create/overwrite rdeps tarball
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rwxr-xr-xgenrdeps-index.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/genrdeps-index.py b/genrdeps-index.py
index 1f0b24c..feea62c 100755
--- a/genrdeps-index.py
+++ b/genrdeps-index.py
@@ -11,6 +11,7 @@ import os.path
import shutil
import subprocess
import sys
+import tempfile
import pkgcore.config
from pkgcore.ebuild.atom import atom
@@ -102,12 +103,24 @@ def main():
os.rename(newdir, outdir)
shutil.rmtree(olddir, onerror=rmtree_ignore_enoent)
- subprocess.check_call(
- ['tar', '-cf', 'rdeps.tar'] + [gi for g, gi in GROUPS],
- cwd=args.outputdir)
- subprocess.check_call(
- ['xz', '-9', 'rdeps.tar'],
- cwd=args.outputdir)
+ with tempfile.NamedTemporaryFile(prefix='.tmp.rdeps-', suffix='.tar', dir=args.outputdir, delete=False) as tmpf:
+ try:
+ subprocess.check_call(
+ ['tar', '-cf', tmpf.name] + [gi for g, gi in GROUPS],
+ cwd=args.outputdir)
+ subprocess.check_call(
+ ['xz', '-9', tmpf.name],
+ cwd=args.outputdir)
+ os.rename(tmpf.name + '.xz', os.path.join(args.outputdir, 'rdeps.tar.xz'))
+ except Exception as e:
+ raise e
+ finally:
+ # Cleanup:
+ for f in [tmpf.name, (tmpf.name + '.xz')]:
+ try:
+ os.unlink(f)
+ except FileNotFoundError as e:
+ pass
return 0