From a38447ba998e839f4b79aebcbce40a1cc5e2b7d0 Mon Sep 17 00:00:00 2001
From: Nikos Skalkotos <skalkoto@grnet.gr>
Date: Thu, 22 Aug 2013 16:26:39 +0300
Subject: [PATCH] In _foreach_file check if the directory exists

Otherwise print a warning.
---
 image_creator/os_type/__init__.py | 4 ++++
 image_creator/os_type/unix.py     | 4 +---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py
index 19e63fc..5298569 100644
--- a/image_creator/os_type/__init__.py
+++ b/image_creator/os_type/__init__.py
@@ -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
diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py
index 8779b76..7255f44 100644
--- a/image_creator/os_type/unix.py
+++ b/image_creator/os_type/unix.py
@@ -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)
 
-- 
GitLab