diff options
| author | jvoisin | 2014-01-27 22:19:50 +0000 |
|---|---|---|
| committer | jvoisin | 2014-01-27 22:19:50 +0000 |
| commit | a8195f5d8034f82aef04d2da223fc0a9c0dc9d38 (patch) | |
| tree | cd62a5e74ac8a18c49a6e214a0d03f44d975380b /MAT | |
| parent | dbc1c736e63797c7e88dcd9187fdb028a8de9e59 (diff) | |
Non-writtables test files are now chmod'ed to be properly removed.
Diffstat (limited to 'MAT')
| -rw-r--r-- | MAT/exceptions.py | 6 | ||||
| -rw-r--r-- | MAT/mat.py | 10 |
2 files changed, 15 insertions, 1 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, |
