scripts/dtrx

branch
trunk
changeset 77
3a1f49be7667
parent 76
705642fcb92c
child 78
978307ec7d11
--- a/scripts/dtrx	Tue Jul 15 22:18:03 2008 -0400
+++ b/scripts/dtrx	Sun Jul 20 20:25:54 2008 -0400
@@ -989,6 +989,13 @@
         self.successes = []
         self.failures = []
 
+    def clean_destination(self, dest_name):
+        try:
+            os.unlink(dest_name)
+        except OSError, error:
+            if error.errno == errno.EISDIR:
+                shutil.rmtree(dest_name, ignore_errors=True)
+
     def abort(self, signal_num, frame):
         signal.signal(signal_num, signal.SIG_IGN)
         print
@@ -1001,11 +1008,7 @@
         for directory in clean_targets:
             os.chdir(directory)
             for path in glob.glob('.dtrx-*'):
-                try:
-                    os.unlink(path)
-                except OSError, error:
-                    if error.errno == errno.EISDIR:
-                        shutil.rmtree(path, ignore_errors=True)
+                self.clean_destination(path)
         sys.exit(1)
 
     def parse_options(self, arguments):
@@ -1088,6 +1091,8 @@
             error = self.action.run(filename, extractor)
             if error:
                 errors.append((extractor.file_type, extractor.encoding, error))
+                if extractor.target is not None:
+                    self.clean_destination(extractor.target)
             else:
                 self.recurse(filename, extractor, self.action)
                 return

mercurial