diff options
| -rw-r--r-- | MAT/exceptions.py | 6 | ||||
| -rw-r--r-- | MAT/mat.py | 10 | ||||
| -rw-r--r-- | test/libtest.py | 2 | ||||
| -rw-r--r-- | test/test.py | 3 |
4 files changed, 19 insertions, 2 deletions
diff --git a/MAT/exceptions.py b/MAT/exceptions.py index 7972f20..47da15c 100644 --- a/MAT/exceptions.py +++ b/MAT/exceptions.py | |||
| @@ -6,3 +6,9 @@ class UnableToRemoveFile(Exception): | |||
| 6 | '''This exception is raised when a file could not be removed | 6 | '''This exception is raised when a file could not be removed |
| 7 | ''' | 7 | ''' |
| 8 | pass | 8 | pass |
| 9 | |||
| 10 | class UnableToWriteFile(Exception): | ||
| 11 | '''This exception is raised when a file | ||
| 12 | can could not be chmod +w | ||
| 13 | ''' | ||
| 14 | pass | ||
| @@ -112,6 +112,13 @@ class XMLParser(xml.sax.handler.ContentHandler): | |||
| 112 | def secure_remove(filename): | 112 | def secure_remove(filename): |
| 113 | ''' Securely remove the file | 113 | ''' Securely remove the file |
| 114 | ''' | 114 | ''' |
| 115 | # I want the file removed, even if it's ro | ||
| 116 | try: | ||
| 117 | os.chmod(filename, 0o777) | ||
| 118 | except OSError: | ||
| 119 | logging.error('Unable to add write rights to %s' % filename) | ||
| 120 | raise MAT.exceptions.UnableToWriteFile | ||
| 121 | |||
| 115 | try: | 122 | try: |
| 116 | if not subprocess.call(['shred', '--remove', filename]): | 123 | if not subprocess.call(['shred', '--remove', filename]): |
| 117 | return True | 124 | return True |
| @@ -122,11 +129,12 @@ def secure_remove(filename): | |||
| 122 | 129 | ||
| 123 | try: | 130 | try: |
| 124 | os.remove(filename) | 131 | os.remove(filename) |
| 125 | return True | ||
| 126 | except OSError: | 132 | except OSError: |
| 127 | logging.error('Unable to remove %s' % filename) | 133 | logging.error('Unable to remove %s' % filename) |
| 128 | raise MAT.exceptions.UnableToRemoveFile | 134 | raise MAT.exceptions.UnableToRemoveFile |
| 129 | 135 | ||
| 136 | return True | ||
| 137 | |||
| 130 | 138 | ||
| 131 | def create_class_file(name, backup, **kwargs): | 139 | def create_class_file(name, backup, **kwargs): |
| 132 | ''' Return a $FILETYPEStripper() class, | 140 | ''' Return a $FILETYPEStripper() class, |
diff --git a/test/libtest.py b/test/libtest.py index cbc807f..c2cb2f1 100644 --- a/test/libtest.py +++ b/test/libtest.py | |||
| @@ -98,7 +98,7 @@ class TestSecureRemove(unittest.TestCase): | |||
| 98 | def test_remove_fail(self): | 98 | def test_remove_fail(self): |
| 99 | ''' test the secure removal of an non-removable file | 99 | ''' test the secure removal of an non-removable file |
| 100 | ''' | 100 | ''' |
| 101 | self.assertRaises(MAT.exceptions.UnableToRemoveFile, MAT.mat.secure_remove, '/NOTREMOVABLE') | 101 | self.assertRaises(MAT.exceptions.UnableToWriteFile, MAT.mat.secure_remove, '/NOTREMOVABLE') |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | class TestArchiveProcessing(test.MATTest): | 104 | class TestArchiveProcessing(test.MATTest): |
diff --git a/test/test.py b/test/test.py index 1641f88..49a657b 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -62,6 +62,9 @@ class MATTest(unittest.TestCase): | |||
| 62 | ''' | 62 | ''' |
| 63 | Remove the tmp folder | 63 | Remove the tmp folder |
| 64 | ''' | 64 | ''' |
| 65 | for root, dirs, files in os.walk(self.tmpdir): | ||
| 66 | for d in dirs + files: | ||
| 67 | os.chmod(os.path.join(root, d), 0o777) | ||
| 65 | shutil.rmtree(self.tmpdir) | 68 | shutil.rmtree(self.tmpdir) |
| 66 | 69 | ||
| 67 | 70 | ||
