From ce66ae38c3fbecdf73151161d894d5c2f7511784 Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos <skalkoto@grnet.gr> Date: Wed, 31 Jul 2013 13:33:38 +0300 Subject: [PATCH] Check if scrubbing is supported Don't try to scrub data unless the used guestfs appliance supports it --- image_creator/os_type/__init__.py | 7 +++++++ image_creator/os_type/unix.py | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index ec4f20d..f3a33d9 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -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: diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py index 8b88b2f..001c90d 100644 --- a/image_creator/os_type/unix.py +++ b/image_creator/os_type/unix.py @@ -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 : -- GitLab