From: Nikos Skalkotos Date: Thu, 22 Aug 2013 13:26:39 +0000 (+0300) Subject: In _foreach_file check if the directory exists X-Git-Tag: 0.5.1~4 X-Git-Url: https://code.grnet.gr/git/snf-image-creator/commitdiff_plain/a38447ba998e839f4b79aebcbce40a1cc5e2b7d0?ds=sidebyside In _foreach_file check if the directory exists Otherwise print a warning. --- 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)