diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-05-14 19:05:41 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-05-14 19:05:41 +0200 |
| commit | c81cabfcbfd2b91a7ce82168fdea4f9af6788b62 (patch) | |
| tree | 32a6a9125249b5bfaa35d38dcb35403c4329a3d8 /lib | |
| parent | 3b7b15f381fbee648784895067cff165f975c360 (diff) | |
| download | slackbuilder-c81cabfcbfd2b91a7ce82168fdea4f9af6788b62.tar.gz | |
Replace extern rm rf call with a function
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/SlackBuilder/Download.hs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/SlackBuilder/Download.hs b/lib/SlackBuilder/Download.hs index 285e389..53e609c 100644 --- a/lib/SlackBuilder/Download.hs +++ b/lib/SlackBuilder/Download.hs @@ -7,6 +7,7 @@ module SlackBuilder.Download ( cloneAndUpload , extractRemote , commit + , createLzmaTarball , download , hostedSources , remoteFileExists @@ -32,7 +33,7 @@ import SlackBuilder.Config import SlackBuilder.Trans import Control.Monad.Trans.Reader (asks) import Control.Monad.IO.Class (MonadIO(liftIO)) -import System.Directory (createDirectory) +import System.Directory (createDirectory, removePathForcibly) import System.IO (IOMode(..), withFile) import System.FilePath ((</>), (<.>), takeFileName, takeDirectory, stripExtension) import System.Process @@ -43,7 +44,7 @@ import System.Process , callProcess ) import System.Exit (ExitCode(..)) -import Control.Monad (unless) +import Control.Monad (unless, void) import Text.URI (URI(..)) import qualified Text.URI as URI import Network.HTTP.Req @@ -55,23 +56,25 @@ import Network.HTTP.Req , defaultHttpConfig , ignoreResponse , responseStatusCode + , MonadHttp , HttpConfig(..) , GET(..) - , reqBr, MonadHttp + , reqBr ) import Data.Functor ((<&>)) import Network.HTTP.Client (BodyReader, Response(..), brRead) import Conduit ( ConduitT + , MonadResource , yield , runConduitRes , sinkFile , (.|) , ZipSink(..) , await - , sourceFile, MonadResource + , sourceFile ) -import Data.Conduit.Tar (untar, FileInfo(..)) +import Data.Conduit.Tar (FileInfo(..), tarFilePath, untar) import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate) import Data.Void (Void) import qualified Data.Conduit.Lzma as Lzma @@ -160,7 +163,7 @@ cloneAndArchive repo tarballPath tagPrefix = do repositoryTarballPath <- relativeToRepository tarballPath repositoryArchivePath <- relativeToRepository $ tarballPath <.> "tar.xz" liftIO - $ callProcess "rm" ["-rf", repositoryTarballPath] + $ removePathForcibly repositoryTarballPath >> callProcess "git" [ "clone" , Text.unpack repo @@ -180,12 +183,14 @@ cloneAndArchive repo tarballPath tagPrefix = do , "--init" , "--recursive" ] - >> callProcess "tar" - ["Jcvf" - , repositoryArchivePath - , repositoryTarballPath - ] - >> callProcess "rm" ["-rf", repositoryTarballPath] + >> createLzmaTarball repositoryTarballPath repositoryArchivePath + >> removePathForcibly repositoryTarballPath + +createLzmaTarball :: FilePath -> FilePath -> IO (Digest MD5) +createLzmaTarball input output = runConduitRes $ yield input + .| void tarFilePath + .| Lzma.compress Nothing + .| sinkFileAndHash output responseBodySource :: MonadIO m => Response BodyReader -> ConduitT i ByteString m () responseBodySource = bodyReaderSource . responseBody |
