From 3d2429a41de44f9769c7f63b587c9f0502fd1a6c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 14 Jul 2013 15:44:20 +0200 Subject: Fiabilise secure_remove + associated tests --- MAT/mat.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'MAT') diff --git a/MAT/mat.py b/MAT/mat.py index 42e96df..def8cb3 100644 --- a/MAT/mat.py +++ b/MAT/mat.py @@ -13,6 +13,8 @@ import xml.sax import hachoir_core.cmd_line import hachoir_parser +import MAT.exceptions + __version__ = '0.4' __author__ = 'jvoisin' @@ -107,18 +109,20 @@ def secure_remove(filename): ''' securely remove the file ''' - removed = False try: - subprocess.call(['shred', '--remove', filename]) - removed = True + if subprocess.call(['shred', '--remove', filename]) == 0: + return True + else: + raise OSError except OSError: logging.error('Unable to securely remove %s' % filename) - if not removed: - try: - os.remove(filename) - except OSError: - logging.error('Unable to remove %s' % filename) + try: + os.remove(filename) + return True + except OSError: + logging.error('Unable to remove %s' % filename) + raise MAT.exceptions.UnableToRemoveFile def create_class_file(name, backup, **kwargs): -- cgit v1.3