Skip to content

Commit d828dc7

Browse files
authored
[ANE-2297] include the archive name in paths for vendored deps and first-party-license scans (#1520)
* update the Changelog
1 parent d4c63f3 commit d828dc7

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# FOSSA CLI Changelog
2+
## 3.10.3
3+
4+
License Scanning: Added the archive name to the path for licenses found inside of archives during vendored dependency and first-party license scanning ([#1520](https://github.com/fossas/fossa-cli/pull/1520))
25

36
## 3.10.2
47

integration-test/Analysis/LicenseScannerSpec.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ spec = do
102102
Success _ us -> do
103103
length us `shouldBe` 3
104104
NE.sort (NE.map licenseUnitName us) `shouldBe` NE.fromList ["No_license_found", "apache-2.0", "mit"]
105-
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo/bar/MIT_LICENSE", "vendor/foo/bar/baz/SOMETHING_LICENSE", "vendor/foo/bar/baz/quux/QUUX_LICENSE"]
106-
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo/bar/bar_apache.rb", "vendor/foo/bar/baz/something.rb"]
105+
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo.tar.gz/foo/bar.tar.gz/bar/MIT_LICENSE", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/SOMETHING_LICENSE", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/quux.tar.gz/quux/QUUX_LICENSE"]
106+
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo.tar.gz/foo/bar.tar.gz/bar/bar_apache.rb", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/something.rb"]
107107
-- matchData should exist
108108
let matchData = concatMap NE.toList $ NE.toList (fromMaybe (NE.fromList []) . licenseUnitDataMatchData <$> licenseUnitData mitUnit)
109109
licenseUnitMatchDataMatchString <$> matchData `shouldBe` [Just mitLicense, Just mitLicense, Just mitLicense]
@@ -125,8 +125,8 @@ spec = do
125125
Success _ us -> do
126126
length us `shouldBe` 3
127127
NE.sort (NE.map licenseUnitName us) `shouldBe` NE.fromList ["No_license_found", "apache-2.0", "mit"]
128-
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo/bar/MIT_LICENSE", "vendor/foo/bar/baz/SOMETHING_LICENSE", "vendor/foo/bar/baz/quux/QUUX_LICENSE"]
129-
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo/bar/bar_apache.rb", "vendor/foo/bar/baz/something.rb"]
128+
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo.tar.gz/foo/bar.tar.gz/bar/MIT_LICENSE", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/SOMETHING_LICENSE", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/quux.tar.gz/quux/QUUX_LICENSE"]
129+
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo.tar.gz/foo/bar.tar.gz/bar/bar_apache.rb", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/something.rb"]
130130
-- We should get Contents since we're running themis with --srclib-with-full-files
131131
licenseUnitDataContents <$> licenseUnitData mitUnit `shouldBe` NE.fromList [Just mitLicense, Just mitLicense, Just mitLicense]
132132
-- matchData should be all Nothing
@@ -149,7 +149,7 @@ spec = do
149149
Success _ us -> do
150150
length us `shouldBe` 1
151151
NE.sort (NE.map licenseUnitName us) `shouldBe` NE.fromList ["apache-2.0"]
152-
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo/bar/bar_apache.rb", "vendor/foo/bar/baz/something.rb"]
152+
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo.tar.gz/foo/bar.tar.gz/bar/bar_apache.rb", "vendor/foo.tar.gz/foo/bar.tar.gz/bar/baz.tar.gz/baz/something.rb"]
153153
where
154154
apacheUnit :: LicenseUnit
155155
apacheUnit = fromMaybe emptyLicenseUnit (head' $ NE.filter (\u -> licenseUnitName u == "apache-2.0") us)

src/App/Fossa/LicenseScanner.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Fossa.API.Types (
7171
OrgId,
7272
Organization (organizationId),
7373
)
74-
import Path (Abs, Dir, File, Path, SomeBase (Abs, Rel), fileExtension, parent, (</>))
74+
import Path (Abs, Dir, File, Path, SomeBase (Abs, Rel), fileExtension, toFilePath, (</>))
7575
import Path.Extra (SomePath (..), tryMakeRelative)
7676
import Prettyprinter (Pretty (pretty))
7777
import Srclib.Types (
@@ -80,6 +80,7 @@ import Srclib.Types (
8080
LicenseUnit (..),
8181
Locator (..),
8282
)
83+
import System.FilePath qualified as FP
8384
import Types (LicenseScanPathFilters (licenseScanPathFilterFileExclude))
8485

8586
data LicenseScanErr
@@ -139,7 +140,7 @@ recursivelyScanArchives ::
139140
recursivelyScanArchives pathPrefix licenseScanPathFilters uploadKind dir = flip walk' dir $
140141
\_ _ files -> do
141142
let process file unpackedDir = do
142-
let updatedPathPrefix = pathPrefix <> getPathPrefix dir (parent file)
143+
let updatedPathPrefix = pathPrefix <> getPathPrefix dir file
143144
currentDirResults <- withThemisAndIndex $ themisRunner updatedPathPrefix licenseScanPathFilters uploadKind unpackedDir
144145
recursiveResults <- recursivelyScanArchives updatedPathPrefix licenseScanPathFilters uploadKind unpackedDir
145146
pure $ currentDirResults <> recursiveResults
@@ -240,7 +241,7 @@ getPathPrefix :: Path Abs Dir -> Path Abs t -> Text
240241
getPathPrefix baseDir scanPath = do
241242
case tryMakeRelative baseDir scanPath of
242243
Path.Abs _ -> Text.empty
243-
Path.Rel path -> toText path
244+
Path.Rel path -> toText $ FP.addTrailingPathSeparator $ toFilePath path
244245

245246
scanArchive ::
246247
( Has Diagnostics sig m
@@ -264,7 +265,7 @@ scanArchive baseDir licenseScanPathFilters uploadKind file = runFinally $ do
264265
Just units -> pure units
265266
where
266267
pathPrefix :: Text
267-
pathPrefix = getPathPrefix baseDir (parent $ scanFile file)
268+
pathPrefix = getPathPrefix baseDir $ scanFile file
268269

269270
scanDirectory ::
270271
( Has Exec sig m

0 commit comments

Comments
 (0)