diff --git a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt index 0c60ebd6eeded..13ab6a5b2718b 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt @@ -191,14 +191,18 @@ class Cargo( ) val nonProjectPackages = packageById.values.mapNotNullTo(mutableSetOf()) { cargoPkg -> - cargoPkg.takeUnless { it.isProject() }?.toPackage(hashes) + cargoPkg.takeUnless { it.isProject(workingDir) }?.toPackage(hashes) } return listOf(ProjectAnalyzerResult(project, nonProjectPackages)) } } -private fun CargoMetadata.Package.isProject() = source == null +private fun CargoMetadata.Package.isProject(root: File? = null): Boolean { + val path = id.substringAfter("path+file://", "").removeSuffix(")").ifEmpty { null } + val isWithinRoot = root != null && path != null && File(path).startsWith(root) + return source == null && isWithinRoot +} private fun CargoMetadata.Package.toPackage(hashes: Map): Package { val declaredLicenses = parseDeclaredLicenses()