diff --git a/molecule/handlers.py b/molecule/handlers.py index 78aa787..bab3d0b 100644 --- a/molecule/handlers.py +++ b/molecule/handlers.py @@ -248,6 +248,15 @@ class ChrootHandler(GenericHandlerInterface): # now remove paths to remove (...) remove_paths = self.metadata.get('paths_to_remove',[]) + + # setup sandbox + sb_dirs = [self.dest_dir] + sb_env = { + 'SANDBOX_WRITE': ':'.join(sb_dirs), + } + myenv = os.environ.copy() + myenv.update(sb_env) + for mypath in remove_paths: mypath = self.dest_dir+mypath self.Output.updateProgress("[%s|%s] %s: %s" % ( @@ -255,7 +264,7 @@ class ChrootHandler(GenericHandlerInterface): _("removing dir"),mypath, ) ) - rc = molecule.utils.remove_path(mypath) + rc = molecule.utils.remove_path_sandbox(mypath, sb_env) if rc != 0: self.Output.updateProgress("[%s|%s] %s: %s: %s" % ( blue("ChrootHandler"),darkred(self.spec_name), diff --git a/molecule/utils.py b/molecule/utils.py index ce94917..728407a 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -19,6 +19,7 @@ from __future__ import with_statement import os +import sys import time import subprocess import shutil @@ -75,5 +76,12 @@ def empty_dir(dest_dir): def remove_path(path): return subprocess.call('rm -rf %s' % (path,), shell = True) +def remove_path_sandbox(path, sandbox_env): + p = subprocess.Popen(["sandbox", "rm", "-rf", path], + stdout = sys.stdout, stderr = sys.stderr, + env = sandbox_env + ) + return p.wait() + def get_random_number(): return abs(hash(os.urandom(2)))%99999