summaryrefslogtreecommitdiff
path: root/lib/archive.py
diff options
context:
space:
mode:
authorjvoisin2011-06-30 18:57:44 +0200
committerjvoisin2011-06-30 18:57:44 +0200
commit3bc343109528964f6bec075e83106d8f54710b99 (patch)
treefec09f0e9eed1a90d8eefdbbd0f0d8754bc815d3 /lib/archive.py
parent56bde32224a8044b0da3c5646b6cc2c112f74479 (diff)
Now tests are green for archives
Diffstat (limited to 'lib/archive.py')
-rw-r--r--lib/archive.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/lib/archive.py b/lib/archive.py
index 789dcb7..7e928f0 100644
--- a/lib/archive.py
+++ b/lib/archive.py
@@ -48,6 +48,23 @@ class TarStripper(parser.Generic_parser):
48 mat.secure_remove(self.filename) 48 mat.secure_remove(self.filename)
49 os.rename(self.filename + parser.POSTFIX, self.filename) 49 os.rename(self.filename + parser.POSTFIX, self.filename)
50 50
51 def is_file_clean(self, current_file):
52 '''
53 Check metadatas added by tar
54 '''
55 if current_file.mtime is not 0:
56 return False
57 elif current_file.uid is not 0:
58 return False
59 elif current_file.gid is not 0:
60 return False
61 elif current_file.uname is not '':
62 return False
63 elif current_file.gname is not '':
64 return False
65 else:
66 return True
67
51 def is_clean(self): 68 def is_clean(self):
52 self.tarin = tarfile.open(self.filename, 'r' + self.compression) 69 self.tarin = tarfile.open(self.filename, 'r' + self.compression)
53 for current_file in self.tarin.getmembers(): 70 for current_file in self.tarin.getmembers():
@@ -58,15 +75,7 @@ class TarStripper(parser.Generic_parser):
58 if not class_file.is_clean(): 75 if not class_file.is_clean():
59 self.folder_list = [] 76 self.folder_list = []
60 return False 77 return False
61 if current_file.mtime is not 0: 78 if not self.is_file_clean(current_file):
62 return False
63 if current_file.uid is not 0:
64 return False
65 if current_file.gid is not 0:
66 return False
67 if current_file.uname is not '':
68 return False
69 if current_file.gname is not '':
70 return False 79 return False
71 mat.secure_remove(current_file.name) 80 mat.secure_remove(current_file.name)
72 else: 81 else:
@@ -83,13 +92,14 @@ class TarStripper(parser.Generic_parser):
83 metadata = {} 92 metadata = {}
84 for current_file in self.tarin.getmembers(): 93 for current_file in self.tarin.getmembers():
85 if current_file.type is '0': 94 if current_file.type is '0':
86 current_meta = {} 95 if not self.is_file_clean(current_file):#if there is meta
87 current_meta['mtime'] = current_file.mtime 96 current_meta = {}
88 current_meta['uid'] = current_file.uid 97 current_meta['mtime'] = current_file.mtime
89 current_meta['gid'] = current_file.gid 98 current_meta['uid'] = current_file.uid
90 current_meta['uname'] = current_file.uname 99 current_meta['gid'] = current_file.gid
91 current_meta['gname'] = current_file.gname 100 current_meta['uname'] = current_file.uname
92 metadata[current_file.name] = current_meta 101 current_meta['gname'] = current_file.gname
102 metadata[current_file.name] = current_meta
93 return metadata 103 return metadata
94 104
95class GzipStripper(TarStripper): 105class GzipStripper(TarStripper):