Skip to content

Commit

Permalink
Merge pull request #2 from rmohr/pipe-errors
Browse files Browse the repository at this point in the history
Check pipe errors when extracting RPMs
  • Loading branch information
rmohr authored Nov 15, 2018
2 parents 3aa3469 + 4fa92ee commit eba32a0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions rpm/install_rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
from os import path


parser = argparse.ArgumentParser(
description='Install RPMs and update the RPM database inside the docker image')

Expand All @@ -18,6 +17,11 @@
parser.add_argument('--output', action='store', required=True,
help=('target archive'))


class RPMError(Exception):
pass


def main():
args = parser.parse_args()
dirpath = tempfile.mkdtemp()
Expand All @@ -35,19 +39,28 @@ def main():

# Register the RPMs in the database
for rpm in args.rpm:
subprocess.check_call(["rpm", "--nosignature", "--dbpath", rpmdb, "-i", "-v", "--ignoresize", "--nodeps", "--noscripts" ,"--notriggers" ,"--excludepath", "/", rpm])
subprocess.check_call(
["rpm", "--nosignature", "--dbpath", rpmdb, "-i", "-v", "--ignoresize", "--nodeps", "--noscripts",
"--notriggers", "--excludepath", "/", rpm])

# Extract the rpms into the shared folder
for rpm in args.rpm:
p1 = subprocess.Popen(["rpm2cpio", rpm], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["cpio", "-i", "-d", "-m", "-v"], stdin=p1.stdout, stdout=subprocess.PIPE, cwd=dirpath)
p2 = subprocess.Popen(["cpio", "-i", "-d", "-m", "-v"], stdin=p1.stdout, stdout=subprocess.PIPE,
cwd=dirpath)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
p2.communicate()
if p1.returncode and p1.returncode != 0:
print(p1.returncode)
raise RPMError("rpm2cpio exited with a non-zero exit code: %d" % p1.returncode)
if p2.returncode and p2.returncode != 0:
raise RPMError("cpio exited with a non-zero exit code: %d" % p2.returncode)

with tarfile.open(args.output, "a") as tar:
tar.add(dirpath, arcname="/")
finally:
shutil.rmtree(dirpath)


if __name__ == '__main__':
main()
main()

0 comments on commit eba32a0

Please sign in to comment.