Make sure to handle deleted prefixes properly
This commit is contained in:
parent
da28bc4ce9
commit
dba75a08af
2 changed files with 33 additions and 1 deletions
|
@ -310,5 +310,32 @@ class TestStreamLayerMerger(unittest.TestCase):
|
||||||
self.assertHasFile(squashed, 'foo/some_file', 'baz')
|
self.assertHasFile(squashed, 'foo/some_file', 'baz')
|
||||||
self.assertDoesNotHaveFile(squashed, 'foo/another_file')
|
self.assertDoesNotHaveFile(squashed, 'foo/another_file')
|
||||||
|
|
||||||
|
def test_delete_directory_prefix(self):
|
||||||
|
third_layer = self.create_layer(
|
||||||
|
foo = 'foobar/some_file',
|
||||||
|
bar = 'foo/another_file')
|
||||||
|
|
||||||
|
second_layer = self.create_layer(
|
||||||
|
_ = 'foo/')
|
||||||
|
|
||||||
|
squashed = self.squash_layers([second_layer, third_layer])
|
||||||
|
|
||||||
|
self.assertHasFile(squashed, 'foobar/some_file', 'foo')
|
||||||
|
self.assertDoesNotHaveFile(squashed, 'foo/another_file')
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_directory_pre_prefix(self):
|
||||||
|
third_layer = self.create_layer(
|
||||||
|
foo = 'foobar/baz/some_file',
|
||||||
|
bar = 'foo/another_file')
|
||||||
|
|
||||||
|
second_layer = self.create_layer(
|
||||||
|
_ = 'foo/')
|
||||||
|
|
||||||
|
squashed = self.squash_layers([second_layer, third_layer])
|
||||||
|
|
||||||
|
self.assertHasFile(squashed, 'foobar/baz/some_file', 'foo')
|
||||||
|
self.assertDoesNotHaveFile(squashed, 'foo/another_file')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -89,9 +89,14 @@ class StreamLayerMerger(object):
|
||||||
# Check if this file has already been encountered somewhere. If so,
|
# Check if this file has already been encountered somewhere. If so,
|
||||||
# skip it.
|
# skip it.
|
||||||
ubsolute = unicode(absolute)
|
ubsolute = unicode(absolute)
|
||||||
if ubsolute in self.path_trie or any(self.prefix_trie.iter_prefixes(ubsolute)):
|
if ubsolute in self.path_trie:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Check if this file is under a deleted path.
|
||||||
|
for prefix in self.prefix_trie.iter_prefixes(ubsolute):
|
||||||
|
if not os.path.relpath(ubsolute, prefix).startswith('..'):
|
||||||
|
return False
|
||||||
|
|
||||||
# Otherwise, add the path to the encountered list and return it.
|
# Otherwise, add the path to the encountered list and return it.
|
||||||
self.path_encountered.append(absolute)
|
self.path_encountered.append(absolute)
|
||||||
return True
|
return True
|
||||||
|
|
Reference in a new issue