[molecule] remaster plugin: do not remove/empty paths before hooks, always kill tmp dir

This commit is contained in:
Fabio Erculiani
2009-10-27 10:57:58 +01:00
parent e6f8062c2a
commit 12a1d83ac9
2 changed files with 67 additions and 47 deletions
+39 -39
View File
@@ -121,6 +121,45 @@ class ChrootHandler(GenericExecutionStep):
)
)
# now remove paths to empty
empty_paths = self.metadata.get('paths_to_empty',[])
for mypath in empty_paths:
mypath = self.dest_dir+mypath
self.Output.updateProgress("[%s|%s] %s: %s" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("emptying dir"),mypath,
)
)
if os.path.isdir(mypath):
molecule.utils.empty_dir(mypath)
# 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" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("removing dir"),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),
_("removal failed for"),mypath,rc,
)
)
return rc
# write release file
release_file = self.metadata.get('release_file')
if isinstance(release_file,basestring) and release_file:
@@ -220,45 +259,6 @@ class ChrootHandler(GenericExecutionStep):
)
return rc
# now remove paths to empty
empty_paths = self.metadata.get('paths_to_empty',[])
for mypath in empty_paths:
mypath = self.dest_dir+mypath
self.Output.updateProgress("[%s|%s] %s: %s" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("emptying dir"),mypath,
)
)
if os.path.isdir(mypath):
molecule.utils.empty_dir(mypath)
# 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" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("removing dir"),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),
_("removal failed for"),mypath,rc,
)
)
return rc
self.Output.updateProgress("[%s|%s] %s" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("hooks completed succesfully"),
+28 -8
View File
@@ -120,7 +120,7 @@ class IsoUnpackHandler(GenericExecutionStep):
)
def dorm():
shutil.rmtree(self.metadata['chroot_unpack_path'], True)
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
# create chroot path
try:
@@ -179,7 +179,7 @@ class IsoUnpackHandler(GenericExecutionStep):
if not success:
try:
shutil.rmtree(self.metadata['chroot_unpack_path'], True)
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
except (shutil.Error, OSError,):
pass
@@ -199,12 +199,13 @@ class ChrootHandler(BuiltinChrootHandler):
self.dest_dir = self.source_dir
return 0
def post_run(self):
self.Output.updateProgress("[%s|%s] %s" % (
blue("ChrootHandler"),darkred(self.spec_name),
_("executing post_run"),
)
)
def kill(self, success = True):
BuiltinChrootHandler.kill(self, success = success)
if not success:
try:
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
except (shutil.Error, OSError,):
pass
return 0
def run(self):
@@ -271,6 +272,15 @@ class CdrootHandler(BuiltinCdrootHandler):
self.source_chroot = self.metadata['chroot_unpack_path']
return 0
def kill(self, success = True):
BuiltinCdrootHandler.kill(self, success = success)
if not success:
try:
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
except (shutil.Error, OSError,):
pass
return 0
class IsoHandler(BuiltinIsoHandler):
def pre_run(self):
@@ -288,6 +298,16 @@ class IsoHandler(BuiltinIsoHandler):
self.chroot_dir = self.source_chroot
return 0
def kill(self, success = True):
BuiltinIsoHandler.kill(self, success = success)
if not success:
try:
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
except (shutil.Error, OSError,):
pass
return 0
class RemasterSpec(GenericSpec):
@staticmethod