commit: 415c65624ff62f5ab139666cd5447bc35e1e9e8b
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri May 20 05:42:43 2016 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri May 20 05:42:43 2016 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=415c6562
replace ad-hoc implementations of clear_dir
A few places copy & paste the logic we have in the clear_dir func.
Punt them with a simple call to clear_dir.
catalyst/base/stagebase.py | 9 +--------
catalyst/targets/netboot2.py | 10 ++--------
catalyst/targets/snapshot.py | 20 ++------------------
3 files changed, 5 insertions(+), 34 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 78e5b94..f0f3ba9 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -3,7 +3,6 @@ import os
import imp
import shutil
import sys
-from stat import ST_UID, ST_GID, ST_MODE
from snakeoil import fileutils
@@ -1202,13 +1201,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
log.warning('not a directory or
does not exist, skipping "empty" operation: %s', x)
continue
log.info('Emptying directory %s', x)
- # stat the dir, delete the dir,
recreate the dir and set
- # the proper perms and ownership
- mystat=os.stat(myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
-
os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(myemp)
self.resume.enable("empty")
def remove(self):
diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py
index da856ba..87dada3 100644
--- a/catalyst/targets/netboot2.py
+++ b/catalyst/targets/netboot2.py
@@ -4,12 +4,10 @@ netboot target, version 2
# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
import os
-import shutil
-from stat import ST_UID, ST_GID, ST_MODE
from catalyst import log
from catalyst.support import (CatalystError, normpath, cmd)
-from catalyst.fileops import ensure_dirs, clear_path
+from catalyst.fileops import (ensure_dirs, clear_dir, clear_path)
from catalyst.base.stagebase import StageBase
@@ -152,11 +150,7 @@ class netboot2(StageBase):
log.info('Emptying directory %s', x)
# stat the dir, delete the dir,
recreate the dir and set
# the proper perms and ownership
- mystat=os.stat(myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
-
os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(myemp)
self.resume.enable("empty")
def set_action_sequence(self):
diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index 7ba94b2..8a9acdd 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -2,17 +2,13 @@
Snapshot target
"""
-import os
-import shutil
-from stat import ST_UID, ST_GID, ST_MODE
-
from DeComp.compress import CompressMap
from catalyst import log
from catalyst.support import normpath, cmd
from catalyst.base.targetbase import TargetBase
from catalyst.base.genbase import GenBase
-from catalyst.fileops import ensure_dirs
+from catalyst.fileops import (clear_dir, ensure_dirs)
class snapshot(TargetBase, GenBase):
@@ -102,16 +98,4 @@ class snapshot(TargetBase, GenBase):
log.info('Cleaning up ...')
def purge(self):
- myemp=self.settings["tmp_path"]
- if os.path.isdir(myemp):
- log.notice('Emptying directory %s', myemp)
- # stat the dir, delete the dir, recreate the dir and set
- # the proper perms and ownership
- mystat=os.stat(myemp)
- # There's no easy way to change flags recursively in
python
- if os.uname()[0] == "FreeBSD":
- os.system("chflags -R noschg "+myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(self.settings['tmp_path'])