space check update and catch no space exception
authorGui Chen <gui.chen@intel.com>
Fri, 6 Jan 2012 05:50:17 +0000 (13:50 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Fri, 6 Jan 2012 07:52:23 +0000 (15:52 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py
tools/mic

index 9f66bc9..05e1ab9 100644 (file)
@@ -268,13 +268,6 @@ class Yum(BackendPlugin, yum.YumBase):
 
         dlpkgs = map(lambda x: x.po, filter(lambda txmbr: txmbr.ts_state in ("i", "u"), self.tsInfo.getMembers()))
 
-        # record the total size of installed pkgs
-        pkgs_total_size = sum(map(lambda x: int(x.size), dlpkgs))
-
-        # check needed size before actually download and install
-        if checksize and pkgs_total_size > checksize:
-            raise CreatorError("Size of specified root partition in kickstart file is too small to install all selected packages.")
-
         # record all pkg and the content
         for pkg in dlpkgs:
             pkg_long_name = "%s-%s.%s.rpm" % (pkg.name, pkg.printVer(), pkg.arch)
@@ -287,16 +280,25 @@ class Yum(BackendPlugin, yum.YumBase):
 
         total_count = len(dlpkgs)
         cached_count = 0
+        download_total_size = 0L
         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:
                 cached_count +=1
 
+        # record the total size of installed pkgs
+        pkgs_total_size = sum(map(lambda x: int(x.installedsize), dlpkgs))
+
+        # check needed size before actually download and install
+        if checksize and pkgs_total_size + download_total_size > checksize:
+            raise CreatorError("No enough space used for downloading and installing")
+
         msger.info("%d packages to be installed, %d packages gotten from cache, %d packages to be downloaded" % (total_count, cached_count, total_count - cached_count))
         try:
             repos = self.repos.listEnabled()
index e7dd6b4..d538395 100644 (file)
@@ -331,13 +331,6 @@ class Zypp(BackendPlugin):
             if not zypp.isKindPattern(item) and not self.inDeselectPackages(item):
                 dlpkgs.append(item)
 
-        # record the total size of installed pkgs
-        pkgs_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
-
-        # check needed size before actually download and install
-        if checksize and pkgs_total_size > checksize:
-            raise CreatorError("Size of specified root partition in kickstart file is too small to install all selected packages.")
-
         # record all pkg and the content
         localpkgs = self.localpkgs.keys()
         for pkg in dlpkgs:
@@ -358,6 +351,7 @@ class Zypp(BackendPlugin):
 
         total_count = len(dlpkgs)
         cached_count = 0
+        download_total_size = 0L
         localpkgs = self.localpkgs.keys()
         msger.info("Checking packages cache and packages integrity ...")
         for po in dlpkgs:
@@ -368,9 +362,17 @@ 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:
                         cached_count += 1
+
+        # record the total size of installed pkgs
+        install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
+        # check needed size before actually download and install
+        if checksize and download_total_size + install_total_size > checksize:
+            raise CreatorError("No enough space used for downloading and installing")
+
         download_count =  total_count - cached_count
         msger.info("%d packages to be installed, %d packages gotten from cache, %d packages to be downloaded" % (total_count, cached_count, download_count))
         try:
index 7b11c16..1a08e85 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -15,7 +15,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc., 59
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-import os, sys
+import os, sys, errno
 from mic import msger, creator
 from mic.utils import cmdln, misc, errors
 from mic.plugin import pluginmgr
@@ -181,6 +181,12 @@ if __name__ == "__main__":
     except KeyboardInterrupt:
         msger.error('\n^C catched, program aborted.')
 
+    # catch 'no space left' exception, etc
+    except IOError, e:
+        if e.errno == errno.ENOSPC:
+            msger.error('\nNo space left on device')
+        raise
+
     except errors.Usage, usage:
         msger.error(str(usage))