From ea944d9255116b663988fd24c38558a5296e36f1 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 22 Jul 2023 02:01:45 +1000 Subject: [PATCH] tools/index: ignore symlinks to avoid duplicate entries 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. --- .../src/Security/Advisories/Generate/HTML.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code/hsec-tools/src/Security/Advisories/Generate/HTML.hs b/code/hsec-tools/src/Security/Advisories/Generate/HTML.hs index f6ac3ec5..58683f24 100644 --- a/code/hsec-tools/src/Security/Advisories/Generate/HTML.hs +++ b/code/hsec-tools/src/Security/Advisories/Generate/HTML.hs @@ -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 ((<&>)) @@ -22,7 +22,7 @@ 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, ()) @@ -30,9 +30,13 @@ import System.FilePath (takeFileName, ()) 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 @@ -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