]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
'tahoe debug catalog-shares': sort SIs and shnums
authorBrian Warner <warner@lothar.com>
Mon, 17 Jan 2011 09:59:32 +0000 (01:59 -0800)
committerBrian Warner <warner@lothar.com>
Mon, 17 Jan 2011 09:59:32 +0000 (01:59 -0800)
Without this, SIs or shnums could be emitted in random order, depending upon
what the filesystem happens to return.

src/allmydata/scripts/debug.py

index bd828ee084826e99e3eafc9405cd5c1fe4ee0e7c..10bfa02402dd070b8b11b439e006c40650c7f7a8 100644 (file)
@@ -654,7 +654,7 @@ def catalog_shares(options):
             # ignore nodes that have storage turned off altogether
             pass
         else:
-            for abbrevdir in abbrevs:
+            for abbrevdir in sorted(abbrevs):
                 if abbrevdir == "incoming":
                     continue
                 abbrevdir = os.path.join(d, abbrevdir)
@@ -663,7 +663,7 @@ def catalog_shares(options):
                 # as possible.
                 try:
                     sharedirs = listdir_unicode(abbrevdir)
-                    for si_s in sharedirs:
+                    for si_s in sorted(sharedirs):
                         si_dir = os.path.join(abbrevdir, si_s)
                         catalog_shares_one_abbrevdir(si_s, si_dir, now, out,err)
                 except:
@@ -672,11 +672,17 @@ def catalog_shares(options):
 
     return 0
 
+def _as_number(s):
+    try:
+        return int(s)
+    except ValueError:
+        return "not int"
+
 def catalog_shares_one_abbrevdir(si_s, si_dir, now, out, err):
     from allmydata.util.encodingutil import listdir_unicode, quote_output
 
     try:
-        for shnum_s in listdir_unicode(si_dir):
+        for shnum_s in sorted(listdir_unicode(si_dir), key=_as_number):
             abs_sharefile = os.path.join(si_dir, shnum_s)
             assert os.path.isfile(abs_sharefile)
             try: