Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e64acf

Browse files
committed
Properly append root path segment #57
Signed-off-by: Jono Yang <[email protected]>
1 parent eb105cb commit 2e64acf

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/commoncode/resource.py

+3-2
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)
2037+
path = posixpath_join(current.path, segment)
2038+
existing = resources_by_path.get(path)
20382039
if not existing:
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

+22
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,28 @@ 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/com.liferay.portal.tika-1.0.22.jar',
1459+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract',
1460+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22',
1461+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com',
1462+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay',
1463+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal',
1464+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika',
1465+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika/internal',
1466+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika/internal/activator',
1467+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika/internal/activator/TikaBundleActivator.class',
1468+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/META-INF',
1469+
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/META-INF/MANIFEST.MF',
1470+
]
1471+
resources = [{'path': path} for path in paths]
1472+
vc = VirtualCodebase(location={'files': resources})
1473+
walked_paths = [r.path for r in vc.walk()]
1474+
assert paths == walked_paths
1475+
14541476

14551477
class TestResource(FileBasedTesting):
14561478
test_data_dir = join(dirname(__file__), 'data')

0 commit comments

Comments
 (0)