calculate_download_size may be used by a user but ctx.config.cached_packages_dir gives exception

This commit is contained in:
Faik Uygur
2009-07-16 12:54:39 +00:00
parent 3537de30f2
commit 195d5c65e7
+13 -7
View File
@@ -80,6 +80,12 @@ def calculate_download_sizes(order):
installdb = pisi.db.installdb.InstallDB()
packagedb = pisi.db.packagedb.PackageDB()
try:
cached_packages_dir = ctx.config.cached_packages_dir()
except OSError:
# happens when cached_packages_dir tried to be created by an unpriviledged user
cached_packages_dir = None
for pkg in [packagedb.get_package(name) for name in order]:
delta = None
@@ -100,13 +106,13 @@ def calculate_download_sizes(order):
pkg_hash = pkg.packageHash
pkg_size = pkg.packageSize
path = util.join_path(ctx.config.cached_packages_dir(), fn)
# check the file and sha1sum to be sure it _is_ the cached package
if os.path.exists(path) and util.sha1_file(path) == pkg_hash:
cached_size += pkg_size
elif os.path.exists("%s.part" % path):
cached_size += os.stat("%s.part" % path).st_size
if cached_packages_dir:
path = util.join_path(cached_packages_dir, fn)
# check the file and sha1sum to be sure it _is_ the cached package
if os.path.exists(path) and util.sha1_file(path) == pkg_hash:
cached_size += pkg_size
elif os.path.exists("%s.part" % path):
cached_size += os.stat("%s.part" % path).st_size
total_size += pkg_size