author |
<albertogli@telpin.com.ar> 2005-03-02 17:54:19 UTC |
committer |
<albertogli@telpin.com.ar> 2005-03-02 17:54:19 UTC |
parent | 3055d9e3195739896dfb756d7ad264c775a6723e |
abk | +10 | -11 |
diff --git a/abk b/abk index 0afb71a..ca3f57f 100644 --- a/abk +++ b/abk @@ -197,6 +197,7 @@ class index_file: def __init__(self, name): self.name = name self.db = {} + self.names = [] def load(self): "Loads data from the file." @@ -205,19 +206,20 @@ class index_file: except IOError: # probably file doesn't exist, ignore return - self.db = cPickle.load(f) + (self.db, self.names) = cPickle.load(f) f.close() def save(self): "Saves the index to the disk." f = open(self.name, 'w') - cPickle.dump(self.db, f, cPickle.HIGHEST_PROTOCOL) + cPickle.dump((self.db, self.names), f, cPickle.HIGHEST_PROTOCOL) f.close() def put_file(self, filename): "Incorporates a file into the index." self.db[filename] = file_info(filename) self.db[filename].load() + self.names.append(filename) def get_file(self, filename): "Get the file_info object for the given filename." @@ -230,7 +232,7 @@ class index_file: def populate(self, root): "Populate the index from a root path." self.put_file(root) - tree = os.walk(root) + tree = os.walk(root, topdown = True) for path, childs, files in tree: for f in files: name = os.path.join(path, f) @@ -297,25 +299,22 @@ srcidx.populate(src_path) srcidx.save() # compare them -skeys = srcidx.db.keys() -dkeys = dstidx.db.keys() updated_files = [] -for f in skeys: - if f not in dkeys or srcidx.db[f].cmp_data(dstidx.db[f]): +for f in srcidx.names: + if f not in dstidx.names or not srcidx.db[f].cmp_data(dstidx.db[f]): # files missing in destination, or data changed dst = os.path.join(dst_path, f) print 'c/u', f, dst quiet_unlink(dst) srcidx.db[f].copy_file(dst) updated_files.append((f, dst)) - elif srcidx.db[f].cmp_mdata(dstidx.db[f]): + elif not srcidx.db[f].cmp_mdata(dstidx.db[f]): # metadata changed updated_files.append((f, dst)) - -for f in dkeys: - if f not in skeys: +for f in dstidx.names: + if f not in srcidx.names: # files in destination and not in source dst = os.path.join(dst_path, f) print 'unlink', f, dst