File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2745,7 +2745,7 @@ class CodebaseResource(
27452745 blank = True ,
27462746 help_text = _ (
27472747 "The path of the resource's parent directory. "
2748- "Set to None for top-level (root) resources. "
2748+ "Set to empty string for top-level (root) resources. "
27492749 "Used to efficiently retrieve a directory's contents."
27502750 ),
27512751 )
Original file line number Diff line number Diff line change @@ -916,6 +916,8 @@ def create_codebase_resources(project, scanned_codebase):
916916 # includes the "root". The `get_path` method is used instead.
917917 if field .name == "path" :
918918 continue
919+ if field .name == "parent_path" :
920+ continue
919921 value = getattr (scanned_resource , field .name , None )
920922 if value is not None :
921923 resource_data [field .name ] = value
@@ -924,6 +926,11 @@ def create_codebase_resources(project, scanned_codebase):
924926 resource_data ["type" ] = CodebaseResource .Type [resource_type ]
925927 resource_path = scanned_resource .get_path (strip_root = True )
926928
929+ parent_path = str (Path (resource_path ).parent )
930+ if parent_path == "." :
931+ parent_path = ""
932+ resource_data ["parent_path" ] = parent_path
933+
927934 codebase_resource , _ = CodebaseResource .objects .get_or_create (
928935 project = project ,
929936 path = resource_path ,
Original file line number Diff line number Diff line change @@ -723,3 +723,21 @@ def test_scanpipe_scancode_resolve_dependencies_no_requirements(self):
723723 resolved_dep = project1 .discovereddependencies .get (name = "bluebird" )
724724 self .assertEqual (resolved_dep , dep_2 )
725725 self .assertEqual (resolved_dep .resolved_to_package , pkg_1 )
726+
727+ def test_scanpipe_pipes_scancode_scan_single_package_correct_parent_path (self ):
728+ project1 = Project .objects .create (name = "Analysis" )
729+ input_location = self .data / "scancode" / "is-npm-1.0.0.tgz"
730+ project1 .copy_input_from (input_location )
731+ run = project1 .add_pipeline ("scan_single_package" )
732+ pipeline = run .make_pipeline_instance ()
733+ exitcode , out = pipeline .execute ()
734+
735+ self .assertEqual (0 , exitcode , msg = out )
736+ self .assertEqual (4 , project1 .codebaseresources .count ())
737+
738+ root = project1 .codebaseresources .get (path = "package" )
739+ self .assertEqual ("" , root .parent_path )
740+ self .assertNotEqual ("codebase" , root .parent_path )
741+
742+ file1 = project1 .codebaseresources .get (path = "package/index.js" )
743+ self .assertEqual ("package" , file1 .parent_path )
You can’t perform that action at this time.
0 commit comments