Use exceptions for error handling
[rarslave2.git] / PAR2Set / NoExtract.py
index c065aa3..9b4ea46 100644 (file)
@@ -64,25 +64,50 @@ class NoExtract (PAR2Set.Base.Base):
        def __repr__ (self):
                return 'NoExtract'
 
+       def update_matches (self):
+               """Updates the contents of instance variables with the current in-filesystem state.
+                  This should be run after any operation which can create or delete files."""
+
+               # A NoExtract set is very different from the other sets in this regard. Since we
+               # don't really have a single file that is protected, it's not likely that "normal"
+               # name matching will work as expected.
+               #
+               # Because of this, we will try to find name matches for every single name that is
+               # protected by this set. This will help to detect .1 files that are produced when
+               # repairing this kind of set.
+
+               # Find "normal" name matched files
+               self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename)
+
+               # Find "extra" name matched files
+               for f in self.prot_matched_files:
+                       f_basename = rsutil.common.get_basename (f)
+                       f_matches = rsutil.common.find_name_matches (self.dir, f_basename)
+
+                       self.name_matched_files = rsutil.common.no_duplicates (self.name_matched_files +
+                                       f_matches)
+
+               # Update the all_files part now
+               self.all_files = rsutil.common.no_duplicates (self.name_matched_files + self.prot_matched_files)
+
        def runAll (self):
                """Run the Repair and Deletion stages, omitting the Extraction stage"""
 
                # Repair Stage
-               ret = self.runVerifyAndRepair ()
-
-               if ret != rsutil.common.SUCCESS:
-                       logging.critical ('Repair stage failed for: %s' % self.p2file)
-                       return -rsutil.common.ECHECK
+               try:
+                       self.runVerifyAndRepair()
+               except (RuntimeError, OSError):
+                       logging.critical('Repair stage failed for: %s' % self.p2file)
+                       raise
 
                self.update_matches ()
 
                # Deletion Stage
-               ret = self.runDelete ()
-
-               if ret != rsutil.common.SUCCESS:
-                       logging.critical ('Deletion stage failed for: %s' % self.p2file)
-                       return -rsutil.common.EDELETE
+               try:
+                       self.runDelete()
+               except (RuntimeError, OSError):
+                       logging.critical('Delete stage failed for: %s' % self.p2file)
+                       raise
 
                logging.info ('Successfully completed: %s' % self.p2file)
-               return rsutil.common.SUCCESS