Skip to content

Commit

Permalink
Don't put files in subdir when extracting (#1425)
Browse files Browse the repository at this point in the history
* Don't put files in subdir
* Changelog
  • Loading branch information
jssblck authored May 3, 2024
1 parent 45c4f63 commit 20aea27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# FOSSA CLI Changelog

## v3.9.16
- Updates parallel embedded binary extractions to be more properly isolated ([#1425](https://github.com/fossas/fossa-cli/pull/1425)).

## v3.9.15
- Change TLS to a version that takes advantage of but does not require 1.2 with EMS.
This will be reverted in six months.
Expand Down
48 changes: 16 additions & 32 deletions src/App/Fossa/EmbeddedBinary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Path (
Path,
Rel,
fromAbsFile,
mkRelDir,
mkRelFile,
parent,
parseRelDir,
Expand Down Expand Up @@ -107,33 +106,16 @@ extractThemisFiles = do
_ <- sendIO $ BL.writeFile (toString $ toPath decompressedThemisIndex) (Lzma.decompress $ toLazy embeddedBinaryThemisIndex)
pure $ ThemisBins themisActual $ applyTag @ThemisIndex decompressedThemisIndex

withBerkeleyBinary ::
( Has (Lift IO) sig m
) =>
(BinaryPaths -> m c) ->
m c
withBerkeleyBinary :: (Has (Lift IO) sig m) => (BinaryPaths -> m c) -> m c
withBerkeleyBinary = withEmbeddedBinary BerkeleyDB

withLernieBinary ::
( Has (Lift IO) sig m
) =>
(BinaryPaths -> m c) ->
m c
withLernieBinary :: (Has (Lift IO) sig m) => (BinaryPaths -> m c) -> m c
withLernieBinary = withEmbeddedBinary Lernie

withMillhoneBinary ::
( Has (Lift IO) sig m
) =>
(BinaryPaths -> m c) ->
m c
withMillhoneBinary :: (Has (Lift IO) sig m) => (BinaryPaths -> m c) -> m c
withMillhoneBinary = withEmbeddedBinary Millhone

withEmbeddedBinary ::
( Has (Lift IO) sig m
) =>
PackagedBinary ->
(BinaryPaths -> m c) ->
m c
withEmbeddedBinary :: (Has (Lift IO) sig m) => PackagedBinary -> (BinaryPaths -> m c) -> m c
withEmbeddedBinary bin = bracket (extractEmbeddedBinary bin) cleanupExtractedBinaries

cleanupExtractedBinaries :: (Has (Lift IO) sig m) => BinaryPaths -> m ()
Expand Down Expand Up @@ -176,20 +158,22 @@ extractedPath bin = case bin of
Lernie -> $(mkRelFile "lernie")
Millhone -> $(mkRelFile "millhone")

-- | Extract to @$TMP/fossa-vendor/<uuid>
-- We used to extract everything to @$TMP/fossa-vendor@, but there's a subtle issue with that.
-- Cleanup is just removing the directory where the file resides, which is fine unless there's
-- more than one active extracted file. Cleanup could potentially kill both while one is in use.
-- Extracting to another subdir means that the cleanup only cleans the uuid subdir.
-- The only downside is that we never cleanup the fossa-vendor directory, which is not an issue,
-- since it should be empty by the time we finish cleanup. The tempfile cleaner on the system
-- should pick it up anyway.
-- | Extract to @$TMP/fossa-vendor-<uuid>/
--
-- This function used to extract everything to @$TMP/fossa-vendor@, but there's a subtle issue with that:
-- cleanup just removes the directory where the file resides, which is fine unless there's
-- more than one active extracted file; in which case cleanup would clobber files in use by another function.
--
-- Extracting to another subdir named with the UUID would mean that the cleanup only cleans the UUID subdir,
-- and also doesn't fully isolate functions.
--
-- Instead, this function just appends the UUID to the directory so that subsequent calls are fully isolated.
extractDir :: Has (Lift IO) sig m => m (Path Abs Dir)
extractDir = do
wd <- sendIO getTempDir
ts <- sendIO $ UUID.toString <$> UUID.nextRandom
subDir <- sendIO $ parseRelDir ts
pure (wd </> $(mkRelDir "fossa-vendor") </> subDir)
subDir <- sendIO . parseRelDir $ "fossa-vendor-" <> ts
pure $ wd </> subDir

makeExecutable :: Path Abs File -> IO ()
makeExecutable path = do
Expand Down

0 comments on commit 20aea27

Please sign in to comment.