diff --git a/test/test_streamlayerformat.py b/test/test_streamlayerformat.py index 5294f2095..4ec639126 100644 --- a/test/test_streamlayerformat.py +++ b/test/test_streamlayerformat.py @@ -310,5 +310,32 @@ class TestStreamLayerMerger(unittest.TestCase): self.assertHasFile(squashed, 'foo/some_file', 'baz') 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__': unittest.main() diff --git a/util/streamlayerformat.py b/util/streamlayerformat.py index cb3bdd3ca..3a4be529e 100644 --- a/util/streamlayerformat.py +++ b/util/streamlayerformat.py @@ -89,9 +89,14 @@ class StreamLayerMerger(object): # Check if this file has already been encountered somewhere. If so, # skip it. 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 + # 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. self.path_encountered.append(absolute) return True