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 @@ -2701,7 +2701,7 @@ class CodebaseResource(
27012701 blank = True ,
27022702 help_text = _ (
27032703 "The path of the resource's parent directory. "
2704- "Set to None for top-level (root) resources. "
2704+ "Set to empty string for top-level (root) resources. "
27052705 "Used to efficiently retrieve a directory's contents."
27062706 ),
27072707 )
Original file line number Diff line number Diff line change @@ -818,6 +818,8 @@ def create_codebase_resources(project, scanned_codebase):
818818 # includes the "root". The `get_path` method is used instead.
819819 if field .name == "path" :
820820 continue
821+ if field .name == "parent_path" :
822+ continue
821823 value = getattr (scanned_resource , field .name , None )
822824 if value is not None :
823825 resource_data [field .name ] = value
@@ -826,6 +828,11 @@ def create_codebase_resources(project, scanned_codebase):
826828 resource_data ["type" ] = CodebaseResource .Type [resource_type ]
827829 resource_path = scanned_resource .get_path (strip_root = True )
828830
831+ parent_path = str (Path (resource_path ).parent )
832+ if parent_path == "." :
833+ parent_path = ""
834+ resource_data ["parent_path" ] = parent_path
835+
829836 codebase_resource , _ = CodebaseResource .objects .get_or_create (
830837 project = project ,
831838 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