Skip to content

Commit

Permalink
tools/index: ignore symlinks to avoid duplicate entries
Browse files Browse the repository at this point in the history
Advisories with multiple affected packages will be defined as a
single file in the "lowest level" package directory, with inbound
symbolic links of the same name in the other package directories.

Update the generate-index command to ignore symbolic links.  This
prevents duplicate entries appearing in the lists/tables.
  • Loading branch information
frasertweedale authored and TristanCacqueray committed Jul 21, 2023
1 parent 5901f53 commit ea944d9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions code/hsec-tools/src/Security/Advisories/Generate/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Security.Advisories.Generate.HTML
)
where

import Control.Monad (forM_)
import Control.Monad (filterM, forM_)
import Control.Monad.Extra (mapMaybeM)
import Data.Either.Extra (eitherToMaybe)
import Data.Functor ((<&>))
Expand All @@ -22,17 +22,21 @@ import Lucid
import Security.Advisories (AttributeOverridePolicy (NoOverrides), OutOfBandAttributes (..), emptyOutOfBandAttributes, parseAdvisory)
import qualified Security.Advisories as Advisories
import Security.Advisories.Git
import System.Directory (createDirectoryIfMissing)
import System.Directory (createDirectoryIfMissing, pathIsSymbolicLink)
import System.Directory.Extra (listFilesRecursive)
import System.FilePath (takeFileName, (</>))

-- * Actions

renderAdvisoriesIndex :: FilePath -> FilePath -> IO ()
renderAdvisoriesIndex src dst = do
let isAdvisory p =
let fileName = takeFileName p
in isPrefixOf "HSEC-" fileName && isSuffixOf ".md" fileName
let okToLoad path = do
isSym <- pathIsSymbolicLink path
let fileName = takeFileName path
pure $
not isSym -- ignore symlinks (avoid duplicates entries in index)
&& "HSEC-" `isPrefixOf` fileName
&& ".md" `isSuffixOf` fileName
readAdvisory path = do
oob <-
getAdvisoryGitInfo path <&> \case
Expand All @@ -44,7 +48,7 @@ renderAdvisoriesIndex src dst = do
}
fileContent <- T.readFile path
return $ eitherToMaybe $ parseAdvisory NoOverrides oob fileContent
advisoriesFileName <- filter isAdvisory <$> listFilesRecursive src
advisoriesFileName <- listFilesRecursive src >>= filterM okToLoad
advisories <- mapMaybeM readAdvisory advisoriesFileName
let renderToFile' path content = do
putStrLn $ "Rendering " <> path
Expand Down

0 comments on commit ea944d9

Please sign in to comment.