summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-01-24 14:34:58 +0100
committerEugen Wissner <belka@caraus.de>2024-01-24 14:34:58 +0100
commit45472a9088ebca45bfffc5228314e3f1f217c4cc (patch)
tree46e18c2ae3d128f3cc9b99f59df30534bc28b5aa
parent2802194063353f7c5e418b22ef51d1019abd32d2 (diff)
downloadslackbuilder-45472a9088ebca45bfffc5228314e3f1f217c4cc.tar.gz
Get the checksum after repackaging
-rw-r--r--lib/SlackBuilder/Download.hs2
-rw-r--r--slackbuilder.cabal8
-rw-r--r--src/Main.hs41
3 files changed, 41 insertions, 10 deletions
diff --git a/lib/SlackBuilder/Download.hs b/lib/SlackBuilder/Download.hs
index 470ce5a..3e22b22 100644
--- a/lib/SlackBuilder/Download.hs
+++ b/lib/SlackBuilder/Download.hs
@@ -9,6 +9,8 @@ module SlackBuilder.Download
, download
, hostedSources
, remoteFileExists
+ , responseBodySource
+ , sinkHash
, updateSlackBuildVersion
, uploadCommand
) where
diff --git a/slackbuilder.cabal b/slackbuilder.cabal
index 5d63512..3d1bc53 100644
--- a/slackbuilder.cabal
+++ b/slackbuilder.cabal
@@ -19,6 +19,8 @@ common dependencies
build-depends:
base >= 4.16 && < 5,
bytestring ^>= 0.11.0,
+ conduit ^>= 1.3.5,
+ http-client ^>= 0.7,
containers ^>= 0.6,
cryptonite >= 0.30,
directory ^>= 1.3.8,
@@ -30,6 +32,8 @@ common dependencies
parser-combinators ^>= 1.3,
process ^>= 1.6.18,
req ^>= 3.13,
+ tar-conduit ^>= 0.4,
+ lzma-conduit ^>= 1.2,
text ^>= 2.0,
tomland ^>= 1.3.3,
transformers ^>= 0.5.6,
@@ -57,10 +61,6 @@ library
SlackBuilder.Package
SlackBuilder.Trans
hs-source-dirs: lib
- build-depends:
- conduit ^>= 1.3.5,
- http-client ^>= 0.7
-
ghc-options: -Wall
executable slackbuilder
diff --git a/src/Main.hs b/src/Main.hs
index 5395fb6..899cfd8 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,6 +6,7 @@ module Main
( main
) where
+import qualified Data.ByteString.Char8 as Char8
import Data.Char (isNumber)
import Control.Applicative (Applicative(liftA2))
import Data.List.NonEmpty (NonEmpty(..))
@@ -30,7 +31,7 @@ import SlackBuilder.Package (Package(..))
import qualified SlackBuilder.Package as Package
import Text.URI (URI(..), mkURI)
import Text.URI.QQ (uri)
-import Data.Foldable (Foldable(..), for_, find)
+import Data.Foldable (Foldable(..), for_, find, traverse_)
import qualified Text.URI as URI
import System.FilePath ((</>), (<.>), dropExtension, takeBaseName, makeRelative, splitFileName)
import SlackBuilder.Info
@@ -51,9 +52,21 @@ import System.Console.ANSI
, Color(..)
, ConsoleLayer(..)
)
-import System.Directory (listDirectory, doesDirectoryExist)
+import System.Directory (listDirectory, doesDirectoryExist, createDirectory)
import Control.Monad (filterM)
import Data.List (isPrefixOf, isSuffixOf, partition)
+import Network.HTTP.Client (Response, BodyReader)
+import Network.HTTP.Req
+ ( runReq
+ , defaultHttpConfig
+ , useHttpsURI
+ , GET(..)
+ , reqBr
+ , NoReqBody(..)
+ )
+import Conduit (runConduitRes, (.|), sinkFile, sourceFile)
+import Data.Conduit.Tar (untar, FileInfo(..))
+import qualified Data.Conduit.Lzma as Lzma
autoUpdatable :: [Package]
autoUpdatable =
@@ -390,12 +403,16 @@ downloadWithTemplate downloadTemplate packagePath version = do
reuploadWithTemplate :: Package.DownloadTemplate -> [CmdSpec] -> Text -> Text -> SlackBuilderT Package.Download
reuploadWithTemplate downloadTemplate commands packagePath version = do
- Package.Download{ download = uri', md5sum = checksum } <-
- downloadWithTemplate downloadTemplate packagePath version
+ repository' <- SlackBuilderT $ asks repository
+ uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
let downloadFileName = URI.unRText
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
relativeTarball = packagePath <> "/" <> downloadFileName
+ tarball = repository' </> Text.unpack relativeTarball
+
+ extractRemote uri'
download' <- handleReupload (Text.unpack relativeTarball) downloadFileName
+ checksum <- liftIO $ runConduitRes $ sourceFile tarball .| sinkHash
pure $ Package.Download download' checksum
where
@@ -407,8 +424,7 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
_ ->
let tarballPath = repository' </> relativeTarball
packedDirectory = takeBaseName $ dropExtension tarballPath
- in liftIO (callProcess "tar" ["xvf", tarballPath])
- >> liftIO (traverse (defaultCreateProcess packedDirectory) commands)
+ in liftIO (traverse (defaultCreateProcess packedDirectory) commands)
>> liftIO (callProcess "tar" ["Jcvf", tarballPath, packedDirectory])
>> uploadTarball relativeTarball downloadFileName
uploadTarball relativeTarball downloadFileName
@@ -434,6 +450,19 @@ reuploadWithTemplate downloadTemplate commands packagePath version = do
, child_user = Nothing
, child_group = Nothing
}
+ extractRemote :: URI -> SlackBuilderT ()
+ extractRemote uri' = traverse_ (runReq defaultHttpConfig . go . fst)
+ $ useHttpsURI uri'
+ go uri' = reqBr GET uri' NoReqBody mempty readResponse
+ readResponse :: Response BodyReader -> IO ()
+ readResponse response = runConduitRes
+ $ responseBodySource response
+ .| Lzma.decompress Nothing
+ .| untar withDecompressedFile
+ withDecompressedFile FileInfo{..}
+ | Char8.last filePath /= '/' =
+ sinkFile (Char8.unpack filePath)
+ | otherwise = liftIO (createDirectory (Char8.unpack filePath))
updatePackage :: Package -> Text -> PackageInfo -> SlackBuilderT ()
updatePackage Package{..} version info = do