From d64f21793cf910168d92de81f27b24723b536daa Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Mon, 26 Jan 2009 13:11:04 +0000 Subject: [PATCH] If file could not be downloaded, raise an error about it. And if it is cached delete it before starting a new operation. It is not deleted after download because it may be checked to see what the problem is. BUG:FIXED:4113 --- pisi/atomicoperations.py | 17 ++++++++++++++++- pisi/package.py | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index e596abe7..6b09a721 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -27,6 +27,7 @@ import pisi.files import pisi.uri import pisi.ui import pisi.version +import pisi.operations.helper import pisi.operations.delta import pisi.db @@ -83,8 +84,10 @@ class Install(AtomicOperation): # If delta exists than use the delta uri. if delta: pkg_uri = delta.packageURI + pkg_hash = delta.packageHash else: pkg_uri = pkg.packageURI + pkg_hash = pkg.packageHash uri = pisi.uri.URI(pkg_uri) if uri.is_absolute_path(): @@ -95,7 +98,19 @@ class Install(AtomicOperation): ctx.ui.info(_("Package URI: %s") % pkg_path, verbose=True) - return Install(pkg_path, ignore_dep) + # Bug 4113 + cached_file = pisi.package.Package.is_cached(pkg_path) + if cached_file and util.sha1_file(cached_file) != pkg_hash: + os.unlink(cached_file) + + install_op = Install(pkg_path, ignore_dep) + + # Bug 4113 + downloaded_file = install_op.package.filepath + if pisi.util.sha1_file(downloaded_file) != pkg_hash: + raise pisi.Error(_("Download Error: Package does not match the repository package.")) + + return install_op else: raise Error(_("Package %s not found in any active repository.") % name) diff --git a/pisi/package.py b/pisi/package.py index a07be855..3e38958a 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -142,3 +142,13 @@ class Package: def comar_dir(self): return os.path.join(self.pkg_dir(), ctx.const.comar_dir) + + @staticmethod + def is_cached(packagefn): + url = pisi.uri.URI(packagefn) + filepath = packagefn + if url.is_remote_file(): + filepath = os.path.join(ctx.config.cached_packages_dir(), url.filename()) + return os.path.exists(filepath) and filepath + else: + return filepath