Check if scrubbing is supported
authorNikos Skalkotos <skalkoto@grnet.gr>
Wed, 31 Jul 2013 10:33:38 +0000 (13:33 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Wed, 31 Jul 2013 10:33:38 +0000 (13:33 +0300)
Don't try to scrub data unless the used guestfs appliance supports
it

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

index ec4f20d..f3a33d9 100644 (file)
@@ -85,6 +85,13 @@ class OSBase(object):
         self.out = output
         self.meta = {}
 
+        # Many guestfs compilations don't support scrub
+        self._scrub_support = True
+        try:
+            self.g.available(['scrub'])
+        except RuntimeError:
+            self._scrub_support = False
+
     def collect_metadata(self):
         """Collect metadata about the OS"""
         try:
index 8b88b2f..001c90d 100644 (file)
@@ -139,12 +139,17 @@ class Unix(OSBase):
             self.out.output("Removing sensitive user data under %s" %
                             " ".join(homedirs))
 
+        action = self.g.rm_rf
+        if self._scrub_support:
+            action = self.g.scrub_file
+        else:
+            self.out.warn("Sensitive data won't be scrubbed (not supported)")
         for homedir in homedirs:
             for data in self.sensitive_userdata:
                 fname = "%s/%s" % (homedir, data)
                 if self.g.is_file(fname):
-                    self.g.scrub_file(fname)
+                    action(fname)
                 elif self.g.is_dir(fname):
-                    self._foreach_file(fname, self.g.scrub_file, ftype='r')
+                    self._foreach_file(fname, action, ftype='r')
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :