Skip to content

Commit d1c5e9d

Browse files
authored
Merge pull request #58 from nexB/fix-virtualcodebase-creation-bug
Fix virtualcodebase creation bug
2 parents eb105cb + 7c417a8 commit d1c5e9d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/commoncode/resource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,12 +2034,13 @@ def _get_parent_directory(self, path_segments):
20342034

20352035
current = self.root
20362036
for segment in path_segments:
2037-
existing = resources_by_path.get(segment)
2038-
if not existing:
2037+
path = posixpath_join(current.path, segment)
2038+
existing = resources_by_path.get(path)
2039+
if not existing or existing == Codebase.CACHED_RESOURCE:
20392040
existing = self._get_or_create_resource(
20402041
name=segment,
20412042
# build the path based on parent
2042-
path=posixpath_join(current.path, segment),
2043+
path=path,
20432044
parent=current,
20442045
is_file=False,
20452046
)

tests/test_resource.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,18 @@ def test_VirtualCodebase_can_be_created_without_RecursionError(self):
14511451
test_file = self.get_test_loc('resource/virtual_codebase/zephyr-binary.json')
14521452
VirtualCodebase(test_file)
14531453

1454+
def test_VirtualCodebase_can_be_created_with_repeated_root_directory(self):
1455+
paths = [
1456+
'to',
1457+
'to/to',
1458+
'to/to/to',
1459+
'to/to/to/to',
1460+
]
1461+
resources = [{'path': path} for path in paths]
1462+
vc = VirtualCodebase(location={'files': resources})
1463+
walked_paths = [r.path for r in vc.walk()]
1464+
assert paths == walked_paths
1465+
14541466

14551467
class TestResource(FileBasedTesting):
14561468
test_data_dir = join(dirname(__file__), 'data')

0 commit comments

Comments
 (0)