1 |
A few places copy & paste the logic we have in the clear_dir func. |
2 |
Punt them with a simple call to clear_dir. |
3 |
--- |
4 |
catalyst/base/stagebase.py | 9 +-------- |
5 |
catalyst/targets/netboot2.py | 10 ++-------- |
6 |
catalyst/targets/snapshot.py | 20 ++------------------ |
7 |
3 files changed, 5 insertions(+), 34 deletions(-) |
8 |
|
9 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
10 |
index 78e5b94..f0f3ba9 100644 |
11 |
--- a/catalyst/base/stagebase.py |
12 |
+++ b/catalyst/base/stagebase.py |
13 |
@@ -3,7 +3,6 @@ import os |
14 |
import imp |
15 |
import shutil |
16 |
import sys |
17 |
-from stat import ST_UID, ST_GID, ST_MODE |
18 |
|
19 |
from snakeoil import fileutils |
20 |
|
21 |
@@ -1202,13 +1201,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
22 |
log.warning('not a directory or does not exist, skipping "empty" operation: %s', x) |
23 |
continue |
24 |
log.info('Emptying directory %s', x) |
25 |
- # stat the dir, delete the dir, recreate the dir and set |
26 |
- # the proper perms and ownership |
27 |
- mystat=os.stat(myemp) |
28 |
- shutil.rmtree(myemp) |
29 |
- ensure_dirs(myemp, mode=0o755) |
30 |
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
31 |
- os.chmod(myemp,mystat[ST_MODE]) |
32 |
+ clear_dir(myemp) |
33 |
self.resume.enable("empty") |
34 |
|
35 |
def remove(self): |
36 |
diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py |
37 |
index da856ba..87dada3 100644 |
38 |
--- a/catalyst/targets/netboot2.py |
39 |
+++ b/catalyst/targets/netboot2.py |
40 |
@@ -4,12 +4,10 @@ netboot target, version 2 |
41 |
# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. |
42 |
|
43 |
import os |
44 |
-import shutil |
45 |
-from stat import ST_UID, ST_GID, ST_MODE |
46 |
|
47 |
from catalyst import log |
48 |
from catalyst.support import (CatalystError, normpath, cmd) |
49 |
-from catalyst.fileops import ensure_dirs, clear_path |
50 |
+from catalyst.fileops import (ensure_dirs, clear_dir, clear_path) |
51 |
|
52 |
from catalyst.base.stagebase import StageBase |
53 |
|
54 |
@@ -152,11 +150,7 @@ class netboot2(StageBase): |
55 |
log.info('Emptying directory %s', x) |
56 |
# stat the dir, delete the dir, recreate the dir and set |
57 |
# the proper perms and ownership |
58 |
- mystat=os.stat(myemp) |
59 |
- shutil.rmtree(myemp) |
60 |
- ensure_dirs(myemp, mode=0o755) |
61 |
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
62 |
- os.chmod(myemp,mystat[ST_MODE]) |
63 |
+ clear_dir(myemp) |
64 |
self.resume.enable("empty") |
65 |
|
66 |
def set_action_sequence(self): |
67 |
diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py |
68 |
index 7ba94b2..8a9acdd 100644 |
69 |
--- a/catalyst/targets/snapshot.py |
70 |
+++ b/catalyst/targets/snapshot.py |
71 |
@@ -2,17 +2,13 @@ |
72 |
Snapshot target |
73 |
""" |
74 |
|
75 |
-import os |
76 |
-import shutil |
77 |
-from stat import ST_UID, ST_GID, ST_MODE |
78 |
- |
79 |
from DeComp.compress import CompressMap |
80 |
|
81 |
from catalyst import log |
82 |
from catalyst.support import normpath, cmd |
83 |
from catalyst.base.targetbase import TargetBase |
84 |
from catalyst.base.genbase import GenBase |
85 |
-from catalyst.fileops import ensure_dirs |
86 |
+from catalyst.fileops import (clear_dir, ensure_dirs) |
87 |
|
88 |
|
89 |
class snapshot(TargetBase, GenBase): |
90 |
@@ -102,16 +98,4 @@ class snapshot(TargetBase, GenBase): |
91 |
log.info('Cleaning up ...') |
92 |
|
93 |
def purge(self): |
94 |
- myemp=self.settings["tmp_path"] |
95 |
- if os.path.isdir(myemp): |
96 |
- log.notice('Emptying directory %s', myemp) |
97 |
- # stat the dir, delete the dir, recreate the dir and set |
98 |
- # the proper perms and ownership |
99 |
- mystat=os.stat(myemp) |
100 |
- # There's no easy way to change flags recursively in python |
101 |
- if os.uname()[0] == "FreeBSD": |
102 |
- os.system("chflags -R noschg "+myemp) |
103 |
- shutil.rmtree(myemp) |
104 |
- ensure_dirs(myemp, mode=0o755) |
105 |
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
106 |
- os.chmod(myemp,mystat[ST_MODE]) |
107 |
+ clear_dir(self.settings['tmp_path']) |
108 |
-- |
109 |
2.8.2 |