From 3ca62f220eeb8c84a5536333117694d1c5a4fa0f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 19 May 2011 11:57:09 +0200 Subject: abrt-action-install-debuginfo: fix for download error Signed-off-by: Denys Vlasenko --- src/plugins/abrt-action-install-debuginfo | 35 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/plugins/abrt-action-install-debuginfo b/src/plugins/abrt-action-install-debuginfo index 75079ff9..2ad0790a 100644 --- a/src/plugins/abrt-action-install-debuginfo +++ b/src/plugins/abrt-action-install-debuginfo @@ -93,9 +93,8 @@ def ask_yes_no(prompt, retries=4): # TODO: unpack just required debuginfo and not entire rpm? # ..that can lead to: foo.c No such file and directory # files is not used... -def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): - package_name = package_nevra + ".rpm" - package_full_path = tmp_dir + "/" + package_name +def unpack_rpm(package_file_name, files, tmp_dir, destdir, keeprpm): + package_full_path = tmp_dir + "/" + package_file_name log1("Extracting %s to %s", package_full_path, destdir) log2("%s", files) print _("Extracting cpio from %s") % (package_full_path) @@ -125,7 +124,7 @@ def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): # and open it for reading unpacked_cpio = open(unpacked_cpio_path, 'rb') - print _("Caching files from %s made from %s") % ("unpacked.cpio", package_name) + print _("Caching files from %s made from %s") % ("unpacked.cpio", package_file_name) cpio = Popen(["cpio", "-idu", "--quiet"], stdin=unpacked_cpio, cwd=destdir, bufsize=-1) retcode = cpio.wait() @@ -309,17 +308,21 @@ class DebugInfoDownload(YumBase): os.makedirs(self.cachedir) local = os.path.join(self.tmpdir, local) pkg.localpath = local # Hack: to set the localpath we want - ret = self.downloadPkgs(pkglist=[pkg]) - # downloadPkgs return an non empty list on succes - if ret: + err = self.downloadPkgs(pkglist=[pkg]) + # normalize the name + # just str(pkg) doesn't work because it can have epoch + pkg_nvra = pkg.name + "-" + pkg.version + "-" + pkg.release + "." + pkg.arch + package_file_name = pkg_nvra + ".rpm" + if err: + # I observed a zero-length file left on error, + # which prevents cleanup later. Fix it: + try: + os.unlink(self.tmpdir + "/" + package_file_name) + except: + pass print (_("Downloading package %s failed") % pkg) else: - # normalize the name - # just str(pkg) doesn't work because it can have epoch - pkg_nvra = (pkg.name + "-" + pkg.version + "-" + - pkg.release + "." + pkg.arch) - - unpack_result = unpack_rpm(pkg_nvra, files, self.tmpdir, + unpack_result = unpack_rpm(package_file_name, files, self.tmpdir, self.cachedir, keeprpms) if unpack_result == RETURN_FAILURE: # recursively delete the temp dir on failure @@ -330,8 +333,10 @@ class DebugInfoDownload(YumBase): downloaded_pkgs += 1 if not self.keeprpms and os.path.exists(self.tmpdir): - print (_("All downloaded packages have been extracted, removing %s") - % self.tmpdir) + # Was: "All downloaded packages have been extracted, removing..." + # but it was appearing even if no packages were in fact extracted + # (say, when there was one package, and it has download error). + print (_("Removing %s") % self.tmpdir) try: os.rmdir(self.tmpdir) except OSError: -- cgit