]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
Narrow the exception handling in cmd-save.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 5 Feb 2010 00:12:30 +0000 (19:12 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 5 Feb 2010 00:12:30 +0000 (19:12 -0500)
If we encountered an error *writing* the pack, we were counting it as a
non-fatal error, which was not the intention.  Only *reading* files we want
to back up should be considered non-fatal.

cmd-save.py

index a88684be22ae470136d837df878cf1b773c9805e..647e2e07207bdd05ec94c92c4028c4c596a30858 100755 (executable)
@@ -4,12 +4,6 @@ import hashsplit, git, options, index
 from helpers import *
 
 
-saved_errors = []
-def add_error(e):
-    saved_errors.append(e)
-    log('\n%s\n' % e)
-
-
 optspec = """
 bup save [-tc] [-n name] <filenames...>
 --
@@ -138,22 +132,30 @@ for (transname,ent) in r.filter(extra):
     elif opt.smaller and ent.size >= opt.smaller:
         add_error('skipping large file "%s"' % ent.name)
     else:
-        try:
-            if stat.S_ISREG(ent.mode):
+        if stat.S_ISREG(ent.mode):
+            try:
                 f = open(ent.name)
-                (mode, id) = hashsplit.split_to_blob_or_tree(w, [f])
+            except IOError, e:
+                add_error(e)
+            except OSError, e:
+                add_error(e)
             else:
-                if stat.S_ISDIR(ent.mode):
-                    assert(0)  # handled above
-                elif stat.S_ISLNK(ent.mode):
-                    (mode, id) = ('120000', w.new_blob(os.readlink(ent.name)))
+                (mode, id) = hashsplit.split_to_blob_or_tree(w, [f])
+        else:
+            if stat.S_ISDIR(ent.mode):
+                assert(0)  # handled above
+            elif stat.S_ISLNK(ent.mode):
+                try:
+                    rl = os.readlink(ent.name)
+                except OSError, e:
+                    add_error(e)
+                except IOError, e:
+                    add_error(e)
                 else:
-                    add_error(Exception('skipping special file "%s"' % ent.name))
-                count += ent.size
-        except IOError, e:
-            add_error(e)
-        except OSError, e:
-            add_error(e)
+                    (mode, id) = ('120000', w.new_blob(rl))
+            else:
+                add_error(Exception('skipping special file "%s"' % ent.name))
+            count += ent.size
         if id:
             ent.validate(id)
             ent.repack()