infocalypse

(djk)
2009-04-05: re-insert fixes.

re-insert fixes.

diff --git a/infocalypse/bundlecache.py b/infocalypse/bundlecache.py
--- a/infocalypse/bundlecache.py
+++ b/infocalypse/bundlecache.py
@@ -51,6 +51,11 @@ def is_writable(dir_name):
             os.remove(tmp_file)
 
 
+class BundleException(Exception):
+    """ An Exception for problems encountered with bundles."""
+    def __init__(self, msg):
+        Exception.__init__(self, msg)
+
 class BundleCache:
     """ Class to create hg bundle files and cache information about
         their sizes. """
diff --git a/infocalypse/insertingbundles.py b/infocalypse/insertingbundles.py
--- a/infocalypse/insertingbundles.py
+++ b/infocalypse/insertingbundles.py
@@ -22,6 +22,7 @@
 
 from graph import graph_to_string, UpToDate, INSERT_SALTED_METADATA, \
      FREENET_BLOCK_LEN
+from bundlecache import BundleException
 
 from statemachine import RequestQueueState
 
@@ -150,10 +151,23 @@ class InsertingBundles(RequestQueueState
         if len(self.new_edges) == 0:
             return None
 
-        edge = self.new_edges.pop()
-        request = self.parent.ctx.make_edge_insert_request(edge, edge,
+        request = None
+        try:
+            edge = self.new_edges.pop()
+            request = self.parent.ctx.make_edge_insert_request(edge, edge,
                                                            self.salting_cache)
-        self.pending[edge] = request
+            self.pending[edge] = request
+        except BundleException, err:
+            if self.parent.ctx.get('REINSERT', 0) > 0:
+                self.parent.ctx.ui_.warn("Couldn't create an identical bundle to "
+                                         + "re-insert.\n"
+                                         + "Maybe the repository was inserted with a "
+                                         + "different version of hg?\n")
+                self.parent.transition(FAILING)
+            else:
+                # Dunno what's going on.
+                raise
+        
         return request
 
     def request_done(self, client, msg):
diff --git a/infocalypse/updatesm.py b/infocalypse/updatesm.py
--- a/infocalypse/updatesm.py
+++ b/infocalypse/updatesm.py
@@ -35,7 +35,7 @@ from fcpmessage import GET_DEF, PUT_FILE
 from requestqueue import RequestQueue
 
 from chk import clear_control_bytes
-from bundlecache import make_temp_file
+from bundlecache import make_temp_file, BundleException
 from graph import INSERT_NORMAL, INSERT_PADDED, INSERT_SALTED_METADATA, \
      minimal_update_graph, graph_to_string, \
      FREENET_BLOCK_LEN, has_version, pull_bundle, parse_graph, hex_version
@@ -230,6 +230,10 @@ class UpdateContext(dict):
             bundle = self.parent.ctx.bundle_cache.make_bundle(self.graph,
                                                           edge[:2],
                                                           tmp_file)
+
+            if bundle[0] != original_len:
+                raise BundleException("Wrong size. Expected: %i. Got: %i"
+                                      % (original_len, bundle[0]))
             assert bundle[0] == original_len
             if pad:
                 out_file = open(tmp_file, 'ab')