From 386a24d150e79f63dfb83d37bc5ca6421e385a60 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Wed, 25 Feb 2009 18:24:42 -0500 Subject: Delete /usr/src/debug files by default (we don't use them.. yet) --- debuginfofs-mirror | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/debuginfofs-mirror b/debuginfofs-mirror index 127b996..9db8c47 100755 --- a/debuginfofs-mirror +++ b/debuginfofs-mirror @@ -80,6 +80,8 @@ class DebuginfoFSDownloader(YumUtilBase): help="download and unpack RPMs even if they already exist") o.add_option("--download-only", default=False, action="store_true", help="download RPMs but don't bother unpacking them") + o.add_option("--keep-src", default=False, action="store_true", + help="keep the contents of /usr/src/debug from each package") def setup(self): self.modify_options() @@ -137,21 +139,25 @@ def fix_perms(targetdir): for f in files: chmod_or(os.path.join(top, f), 0444) -def _unpack_rpm(rpm, targetdir): +def _unpack_rpm(rpm, targetdir, includepat=None, excludepat=None): '''Unpack the given rpm into the given directory''' if not os.path.isdir(targetdir): os.makedirs(targetdir,mode=0755) os.chdir(targetdir) - # rpm2cpio $rpm | cpio --quiet -iumd + cpio = ['cpio','--quiet','-iumd'] + if excludepat: + cpio += ['-f', excludepat] + if includepat: + cpio += [includepat] p1 = Popen(['rpm2cpio',rpm], stdout=PIPE) - p2 = Popen(['cpio','--quiet','-iumd'], stdin=p1.stdout, stdout=PIPE) + p2 = Popen(cpio, stdin=p1.stdout, stdout=PIPE) output = p2.communicate()[0] # should be empty if p2.returncode != 0: raise OSError, "cpio failed: %s output:\n%s" % (str(p2.returncode),output) # Fix perms so all files are readable fix_perms(targetdir) -def unpack_rpm(rpm, targetdir): +def unpack_rpm(rpm, targetdir, includepat=None, excludepat=None): '''Unpack the given rpm into a temporary directory alongside the targetdir, then rename the temp dir once finished.''' dir = os.path.dirname(targetdir) @@ -159,7 +165,7 @@ def unpack_rpm(rpm, targetdir): os.makedirs(targetdir,mode=0755) tmpdir = tempfile.mkdtemp(dir=dir) try: - _unpack_rpm(rpm, tmpdir) + _unpack_rpm(rpm, tmpdir, includepat, excludepat) if os.path.isdir(targetdir): shutil.rmtree(targetdir) os.rename(tmpdir,targetdir) @@ -313,6 +319,9 @@ def main(): sys.exit(1) # Download, unpack, and hardlink debuginfo data + excludepat=None + if not opt.keep_src: + excludepat="*/usr/src/debug/*" for p in unpack_packages + download_packages: if p in download_packages: repo = y.repos.getRepo(p.repoid) @@ -327,7 +336,7 @@ def main(): targetdir = os.path.join(opt.exportdir,'packages',newdir) y.verbose_logger.info("Unpacking %s" % nevra) - unpack_rpm(local, targetdir) + unpack_rpm(local, targetdir, excludepat=excludepat) # Remove cached package now that we've unpacked it if not opt.savecache: os.unlink(local) -- cgit