[Pkg-bazaar-commits] ./bzr/unstable r172: - clearer check against attempts to introduce directory loops in the inventory
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:51:18 UTC 2009
------------------------------------------------------------
revno: 172
committer: mbp at sourcefrog.net
timestamp: Tue 2005-04-05 19:05:32 +1000
message:
- clearer check against attempts to introduce directory loops in the inventory
modified:
bzrlib/inventory.py
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2005-04-01 08:22:11 +0000
+++ b/bzrlib/inventory.py 2005-04-05 09:05:32 +0000
@@ -499,6 +499,22 @@
return 0
+ def get_idpath(self, file_id):
+ """Return a list of file_ids for the path to an entry.
+
+ The list contains one element for each directory followed by
+ the id of the file itself. So the length of the returned list
+ is equal to the depth of the file in the tree, counting the
+ root directory as depth 0.
+ """
+ p = []
+ while file_id != None:
+ ie = self._byid[file_id]
+ p.insert(0, ie.file_id)
+ file_id = ie.parent_id
+ return p
+
+
def id2path(self, file_id):
"""Return as a list the path to file_id."""
p = []
@@ -556,6 +572,11 @@
if new_name in new_parent.children:
bailout("%r already exists in %r" % (new_name, self.id2path(new_parent_id)))
+ new_parent_idpath = self.get_idpath(new_parent_id)
+ if file_id in new_parent_idpath:
+ bailout("cannot move directory %r into a subdirectory of itself, %r"
+ % (self.id2path(file_id), self.id2path(new_parent_id)))
+
file_ie = self._byid[file_id]
old_parent = self._byid[file_ie.parent_id]
More information about the Pkg-bazaar-commits
mailing list