consolidator: add more verbose traversal of directories

This commit is contained in:
Brian Warner 2009-03-12 16:29:00 -07:00
parent 760688a224
commit 1c24707f19
3 changed files with 14 additions and 4 deletions

View File

@ -222,7 +222,7 @@ class Consolidator:
# readonly directory (which shares common subdirs with previous
# backups)
self.msg(" %s: processing" % rwname)
readcap = self.process_directory(readonly(writecap))
readcap = self.process_directory(readonly(writecap), (rwname,))
if self.options["really"]:
self.msg(" replaced %s" % rwname)
self.put_child(archives_dircap, rwname, readcap)
@ -241,7 +241,7 @@ class Consolidator:
% (self.directories_created, self.directories_used_as_is,
self.directories_reused))
def process_directory(self, readcap):
def process_directory(self, readcap, path):
# I walk all my children (recursing over any subdirectories), build
# up a table of my contents, then see if I can re-use an old
# directory with the same contents. If not, I create a new directory
@ -257,7 +257,9 @@ class Consolidator:
for (childname, (childtype, childdata)) in sorted(data["children"].items()):
if childtype == "dirnode":
num_dirs += 1
childcap = self.process_directory(str(childdata["ro_uri"]))
childpath = path + (childname,)
childcap = self.process_directory(str(childdata["ro_uri"]),
childpath)
contents[childname] = ("dirnode", childcap, None)
else:
childcap = str(childdata["ro_uri"])
@ -267,17 +269,23 @@ class Consolidator:
dirhash = self.hash_directory_contents(hashkids)
old_dircap = self.get_old_dirhash(dirhash)
if old_dircap:
if self.options["verbose"]:
self.msg(" %s: reused" % "/".join(path))
assert isinstance(old_dircap, str)
self.directories_reused += 1
return old_dircap
if num_dirs == 0:
# we're allowed to re-use this directory
# we're allowed to use this directory as-is
if self.options["verbose"]:
self.msg(" %s: used as-is" % "/".join(path))
new_dircap = readonly(readcap)
assert isinstance(new_dircap, str)
self.store_dirhash(dirhash, new_dircap)
self.directories_used_as_is += 1
return new_dircap
# otherwise, we need to create a new directory
if self.options["verbose"]:
self.msg(" %s: created" % "/".join(path))
new_dircap = readonly(self.mkdir(contents))
assert isinstance(new_dircap, str)
self.store_dirhash(dirhash, new_dircap)

View File

@ -768,6 +768,7 @@ class ConsolidateOptions(VDriveOptions):
]
optFlags = [
("really", None, "Really remove old snapshot directories"),
("verbose", "v", "Emit a line for every directory examined"),
]
def parseArgs(self, where):
self.where = where

View File

@ -170,6 +170,7 @@ class Consolidate(GridTestMixin, CLITestMixin, unittest.TestCase):
self.do_cli_good("debug", "consolidate",
"--dbfile", dbfile,
"--backupfile", backupfile,
"--verbose",
"tahoe:"))
def _check_consolidate_output1(out):
lines = out.splitlines()