Skip to content

Commit

Permalink
Properly append root path segment #57
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Aug 24, 2023
1 parent eb105cb commit 2e64acf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/commoncode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,12 +2034,13 @@ def _get_parent_directory(self, path_segments):

current = self.root
for segment in path_segments:
existing = resources_by_path.get(segment)
path = posixpath_join(current.path, segment)
existing = resources_by_path.get(path)
if not existing:
existing = self._get_or_create_resource(
name=segment,
# build the path based on parent
path=posixpath_join(current.path, segment),
path=path,
parent=current,
is_file=False,
)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,28 @@ def test_VirtualCodebase_can_be_created_without_RecursionError(self):
test_file = self.get_test_loc('resource/virtual_codebase/zephyr-binary.json')
VirtualCodebase(test_file)

def test_VirtualCodebase_can_be_created_with_repeated_root_directory(self):
paths = [
'to',
'to/to',
'to/to/com.liferay.portal.tika-1.0.22.jar',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika/internal',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/com/liferay/portal/tika/internal/activator',
'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',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/META-INF',
'to/to/com.liferay.portal.tika-1.0.22.jar-extract/com.liferay.portal.tika-1.0.22/META-INF/MANIFEST.MF',
]
resources = [{'path': path} for path in paths]
vc = VirtualCodebase(location={'files': resources})
walked_paths = [r.path for r in vc.walk()]
assert paths == walked_paths


class TestResource(FileBasedTesting):
test_data_dir = join(dirname(__file__), 'data')
Expand Down

0 comments on commit 2e64acf

Please sign in to comment.