From 6d37076b16c6debc54ea3653f2f4c9f893a00684 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Mon, 17 Apr 2023 16:06:43 +0200 Subject: [PATCH] Fix #42: use patches for revisions --- app/Foliage/CmdBuild.hs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/Foliage/CmdBuild.hs b/app/Foliage/CmdBuild.hs index 067895a..08fa2ad 100644 --- a/app/Foliage/CmdBuild.hs +++ b/app/Foliage/CmdBuild.hs @@ -6,7 +6,7 @@ module Foliage.CmdBuild (cmdBuild) where import Codec.Archive.Tar qualified as Tar import Codec.Archive.Tar.Entry qualified as Tar import Codec.Compression.GZip qualified as GZip -import Control.Monad (unless, void, when) +import Control.Monad (foldM, unless, void, when) import Data.Aeson qualified as Aeson import Data.ByteString qualified as BS import Data.ByteString.Lazy qualified as BL @@ -113,9 +113,22 @@ buildAction cf <- prepareIndexPkgCabal pkgId cabalFileTimestamp originalCabalFilePath -- all revised cabal files, with their timestamp - revcf <- for cabalFileRevisions $ uncurry (prepareIndexPkgCabal pkgId) - - return $ cf : revcf + revcf <- + foldM + ( \(lastRevisionPath, cabalFiles) (timestamp, revisionPath) -> do + if takeExtension originalCabalFilePath `elem` [".diff", ".patch"] + then do + patchedRevisionPath <- applyPatch lastRevisionPath revisionPath + preparedCabal <- prepareIndexPkgCabal pkgId timestamp patchedRevisionPath + return (patchedRevisionPath, cabalFiles ++ [preparedCabal]) + else do + preparedCabal <- prepareIndexPkgCabal pkgId timestamp revisionPath + return (revisionPath, cabalFiles ++ [preparedCabal]) + ) + (originalCabalFilePath, []) + (sortOn fst cabalFileRevisions) + + return $ cf : snd revcf ) packageVersions @@ -312,3 +325,9 @@ mkTarEntry contents indexFile timestamp = anchorPath :: Path Absolute -> (RepoLayout -> RepoPath) -> FilePath anchorPath outputDirRoot p = toFilePath $ anchorRepoPathLocally outputDirRoot $ p hackageRepoLayout + +applyPatch :: FilePath -> FilePath -> Action FilePath +applyPatch originalFilePath patchFilePath = do + withTempFile $ \outputFilePath -> do + cmd_ ["patch", "-i", patchFilePath, "-o", outputFilePath, originalFilePath] + return outputFilePath