In _foreach_file check if the directory exists
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 22 Aug 2013 13:26:39 +0000 (16:26 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 22 Aug 2013 13:26:39 +0000 (16:26 +0300)
Otherwise print a warning.

image_creator/os_type/__init__.py
image_creator/os_type/unix.py

index 19e63fc..5298569 100644 (file)
@@ -320,6 +320,10 @@ class OSBase(object):
 
         * exclude: Exclude all files that follow this pattern.
         """
+        if not self.image.g.is_dir(directory):
+            self.out.warn("Directory: `%s' does not exist!" % directory)
+            return
+
         maxdepth = None if 'maxdepth' not in kargs else kargs['maxdepth']
         if maxdepth == 0:
             return
index 8779b76..7255f44 100644 (file)
@@ -108,9 +108,7 @@ class Unix(OSBase):
     def cleanup_mail(self):
         """Remove all files under /var/mail and /var/spool/mail"""
 
-        if self.image.g.is_dir('/var/spool/mail'):
-            self._foreach_file('/var/spool/mail', self.image.g.rm_rf,
-                               maxdepth=1)
+        self._foreach_file('/var/spool/mail', self.image.g.rm_rf, maxdepth=1)
 
         self._foreach_file('/var/mail', self.image.g.rm_rf, maxdepth=1)