diff options
author | Ludwig Hähne <pankrat@tigris.org> | 2008-09-03 16:18:49 (GMT) |
---|---|---|
committer | Ludwig Hähne <pankrat@tigris.org> | 2008-09-03 16:18:49 (GMT) |
commit | 43528ea6633d5d0d2005de38298b45d631642436 (patch) | |
tree | 09549e9b8a8ce0dc9891a8b5d439895b8013b502 | |
parent | 9946a5cb4b0e73b12aaec78e2c25a4c3dc81a6a7 (diff) | |
download | SCons-43528ea6633d5d0d2005de38298b45d631642436.zip SCons-43528ea6633d5d0d2005de38298b45d631642436.tar.gz SCons-43528ea6633d5d0d2005de38298b45d631642436.tar.bz2 |
Issue 2177: Dir get_contents changed to return list of signatures
-rw-r--r-- | src/engine/SCons/Node/FS.py | 21 | ||||
-rw-r--r-- | src/engine/SCons/Node/FSTests.py | 27 |
2 files changed, 45 insertions, 3 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index a2c7244..eda6e71 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1593,9 +1593,24 @@ class Dir(Base): return None def get_contents(self): - """Return aggregate contents of all our children.""" - contents = map(lambda n: n.get_contents(), self.children()) - return string.join(contents, '') + """Return content signatures and names of all our children + separated by new-lines. Ensure that the nodes are sorted.""" + contents = [] + name_cmp = lambda a, b: cmp(a.name, b.name) + sorted_children = self.children()[:] + sorted_children.sort(name_cmp) + for node in sorted_children: + contents.append('%s %s\n' % (node.get_csig(), node.name)) + return string.join(contents, '') + + def get_csig(self): + """Compute the content signature for Directory nodes. In + general, this is not needed and the content signature is not + stored in the DirNodeInfo. However, if get_contents on a Dir + node is called which has a child directory, the child + directory should return the hash of its contents.""" + contents = self.get_contents() + return SCons.Util.MD5signature(contents) def do_duplicate(self, src): pass diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index cfdc978..9d3cabb 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1689,6 +1689,33 @@ class DirTestCase(_tempdirTestCase): os.path.join('ddd', 'f2'), os.path.join('ddd', 'f3')], kids + def test_get_contents(self): + """Test getting the contents for a directory. + """ + test = self.test + + test.subdir('d') + test.write(['d', 'g'], "67890\n") + test.write(['d', 'f'], "12345\n") + test.subdir(['d','sub']) + test.write(['d', 'sub','h'], "abcdef\n") + test.subdir(['d','empty']) + + d = self.fs.Dir('d') + g = self.fs.File(os.path.join('d', 'g')) + f = self.fs.File(os.path.join('d', 'f')) + h = self.fs.File(os.path.join('d', 'sub', 'h')) + e = self.fs.Dir(os.path.join('d', 'empty')) + s = self.fs.Dir(os.path.join('d', 'sub')) + + files = d.get_contents().split('\n') + + assert e.get_contents() == '', e.get_contents() + assert e.get_csig()+" empty" == files[0], files + assert f.get_csig()+" f" == files[1], files + assert g.get_csig()+" g" == files[2], files + assert s.get_csig()+" sub" == files[3], files + def test_implicit_re_scans(self): """Test that adding entries causes a directory to be re-scanned """ |