From 0e5951eedebd2f0d3991454f7bcaf5f7f749cb06 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 14 Nov 2021 03:17:10 +0100 Subject: config option: don't copy asset files --- lib/WriteRepo.hs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'lib/WriteRepo.hs') diff --git a/lib/WriteRepo.hs b/lib/WriteRepo.hs index 1ed3a84..52f0736 100644 --- a/lib/WriteRepo.hs +++ b/lib/WriteRepo.hs @@ -8,12 +8,14 @@ module WriteRepo where import CheckDir (DirResult (dirresultMaps), resultIsFatal) import CheckMap (MapResult (mapresultAdjusted, mapresultDepends)) -import Control.Monad (forM_) +import Control.Monad (forM_, unless) import Data.Aeson (encodeFile) import Data.Map.Strict (toList) import Data.Maybe (mapMaybe) import Data.Set (Set) import qualified Data.Set as S +import LintConfig (LintConfig (configDontCopyAssets), + LintConfig') import Paths (normalise) import System.Directory.Extra (copyFile, createDirectoryIfMissing) import System.Exit (ExitCode (..)) @@ -23,9 +25,9 @@ import System.FilePath.Posix (()) import Types (Dep (Local)) -writeAdjustedRepository :: FilePath -> FilePath -> DirResult -> IO ExitCode -writeAdjustedRepository inPath outPath result - | resultIsFatal result = do +writeAdjustedRepository :: LintConfig' -> FilePath -> FilePath -> DirResult -> IO ExitCode +writeAdjustedRepository config inPath outPath result + | resultIsFatal result && not (configDontCopyAssets config) = do putStrLn "FATAL: Repository has missing assets; cannot write to outPath" pure (ExitFailure 1) | otherwise = do @@ -36,25 +38,26 @@ writeAdjustedRepository inPath outPath result (\(path,out) -> encodeFile (outPath path) $ mapresultAdjusted out) (toList $ dirresultMaps result) - -- collect asset dependencies of maps - -- TODO: its kinda weird doing that here, tbh - let localdeps :: Set FilePath = - S.fromList . concatMap + unless (configDontCopyAssets config) $ do + -- collect asset dependencies of maps + -- TODO: its kinda weird doing that here, tbh + let localdeps :: Set FilePath = + S.fromList . concatMap (\(mappath,mapresult) -> let mapdir = takeDirectory mappath in mapMaybe (\case Local path -> Just . normalise mapdir $ path _ -> Nothing) $ mapresultDepends mapresult) - . toList $ dirresultMaps result - - -- copy all assets - forM_ localdeps $ \path -> - let - assetPath = FP.normalise $ inPath path - newPath = FP.normalise $ outPath path - in do - putStrLn $ "copying " <> assetPath <> " → " <> newPath - copyFile assetPath newPath + . toList $ dirresultMaps result + + -- copy all assets + forM_ localdeps $ \path -> + let + assetPath = FP.normalise $ inPath path + newPath = FP.normalise $ outPath path + in do + putStrLn $ "copying " <> assetPath <> " → " <> newPath + copyFile assetPath newPath pure ExitSuccess -- cgit v1.2.3