From de3a109edb3a1e4cf47b9f5a4edc8edfb89eeda6 Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Tue, 10 Jan 2012 17:22:51 +0800 Subject: [PATCH] Correct algorithm to caculate download packages size --- plugins/backend/yumpkgmgr.py | 11 ++++++++--- plugins/backend/zypppkgmgr.py | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/backend/yumpkgmgr.py b/plugins/backend/yumpkgmgr.py index 08687b4..9a259b8 100644 --- a/plugins/backend/yumpkgmgr.py +++ b/plugins/backend/yumpkgmgr.py @@ -280,20 +280,25 @@ class Yum(BackendPlugin, yum.YumBase): total_count = len(dlpkgs) cached_count = 0 - download_total_size = 0L + download_total_size = sum(map(lambda x: int(x.packagesize), dlpkgs)) msger.info("\nChecking packages cache and packages integrity ...") for po in dlpkgs: local = po.localPkg() if not os.path.exists(local): continue if not self.verifyPkg(local, po, False): - download_total_size += po.downloadSize() msger.warning("Package %s is damaged: %s" % (os.path.basename(local), local)) else: + download_total_size -= int(po.packagesize) cached_count +=1 # record the total size of installed pkgs - pkgs_total_size = sum(map(lambda x: int(x.size), dlpkgs)) + pkgs_total_size = 0L + for x in dlpkgs: + if hasattr(x, 'installedsize'): + pkgs_total_size += int(x.installedsize) + else: + pkgs_total_size += int(x.size) # check needed size before actually download and install if checksize and pkgs_total_size + download_total_size > checksize: diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py index d538395..e46a678 100644 --- a/plugins/backend/zypppkgmgr.py +++ b/plugins/backend/zypppkgmgr.py @@ -351,7 +351,7 @@ class Zypp(BackendPlugin): total_count = len(dlpkgs) cached_count = 0 - download_total_size = 0L + download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs)) localpkgs = self.localpkgs.keys() msger.info("Checking packages cache and packages integrity ...") for po in dlpkgs: @@ -362,9 +362,9 @@ class Zypp(BackendPlugin): local = self.getLocalPkgPath(po) if os.path.exists(local): if self.checkPkg(local) != 0: - download_total_size += po.downloadSize() os.unlink(local) else: + download_total_size -= int(po.downloadSize()) cached_count += 1 # record the total size of installed pkgs -- 2.7.4