From: Brian Warner Date: Mon, 17 Jan 2011 09:59:32 +0000 (-0800) Subject: 'tahoe debug catalog-shares': sort SIs and shnums X-Git-Url: https://git.rkrishnan.org/%5B/frontends/%22file:/flags/statistics?a=commitdiff_plain;h=980fb0b2bbb8b8e1f8217084d1e162f7fd85bed4;p=tahoe-lafs%2Ftahoe-lafs.git 'tahoe debug catalog-shares': sort SIs and shnums Without this, SIs or shnums could be emitted in random order, depending upon what the filesystem happens to return. --- diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index bd828ee0..10bfa024 100644 --- a/src/allmydata/scripts/debug.py +++ b/src/allmydata/scripts/debug.py @@ -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: