diff --git a/Application.hs b/Application.hs index 8b235bc..c8bcec5 100644 --- a/Application.hs +++ b/Application.hs @@ -134,7 +134,7 @@ makeFoundation conf = do runDB' = runResourceT . flip (Database.Persist.runPool dbconf) p uploadHistory0 <- runDB' $ selectSource [] [] $$ sinkUploadHistory UploadState uploadHistory newUploads <- loadCabalFiles uploadHistory0 - runDB' $ mapM_ insert newUploads + runDB' $ mapM_ insert_ newUploads let views = [ ("pvp", viewPVP uploadHistory) , ("no-bounds", viewNoBounds) diff --git a/Handler/Aliases.hs b/Handler/Aliases.hs index 11583e8..bf4a9f3 100644 --- a/Handler/Aliases.hs +++ b/Handler/Aliases.hs @@ -10,7 +10,7 @@ putAliasesR = do aliases <- mapM (parseAlias uid) $ lines aliasesText runDB $ do deleteWhere [AliasUser ==. uid] - mapM_ insert aliases + mapM_ insert_ aliases setMessage "Aliases updated" redirect ProfileR diff --git a/Handler/UploadStackage.hs b/Handler/UploadStackage.hs index 715cc4a..3f63b2e 100644 --- a/Handler/UploadStackage.hs +++ b/Handler/UploadStackage.hs @@ -18,6 +18,8 @@ import Control.Monad.State.Strict (execStateT, get, put) import qualified Codec.Compression.GZip as GZip import Control.Monad.Trans.Resource (unprotect, allocate) import System.Directory (removeFile, getTemporaryDirectory) +import System.Process (runProcess, waitForProcess) +import System.Exit (ExitCode (ExitSuccess)) fileKey :: Text fileKey = "stackage" @@ -81,12 +83,22 @@ putUploadStackageR = do , lsFiles = mempty , lsIdent = ident } - entries <- liftIO $ Tar.pack dir $ map fpToString $ setToList files - let indexLBS = GZip.compress $ Tar.write entries - sourceLazy indexLBS $$ storeWrite (CabalIndex ident) - runDB $ insert stackage + withSystemTempFile "newindex" $ \fp h -> do + ec <- liftIO $ do + hClose h + let args = "cfz" + : fp + : map fpToString (setToList files) + ph <- runProcess "tar" args (Just dir) Nothing Nothing Nothing Nothing + waitForProcess ph + if ec == ExitSuccess + then do + sourceFile (fpFromString fp) $$ storeWrite (CabalIndex ident) + runDB $ insert stackage - done "Stackage created" $ StackageHomeR ident + done "Stackage created" $ StackageHomeR ident + else do + done "Error creating index file" ProfileR redirect $ ProgressR key where diff --git a/stackage-server.cabal b/stackage-server.cabal index 0e32bca..23e93a3 100644 --- a/stackage-server.cabal +++ b/stackage-server.cabal @@ -93,7 +93,7 @@ library , fast-logger >= 2.1.4 && < 2.2 , wai >= 2.1 && < 2.2 , wai-logger >= 2.1 && < 2.2 - , classy-prelude-yesod >= 0.9 && < 0.9.1 + , classy-prelude-yesod >= 0.9.2 && < 0.9.3 , mwc-random >= 0.13 && < 0.14 , mtl >= 2.1 && < 2.2 , blaze-markup >= 0.6 && < 0.7 @@ -119,6 +119,7 @@ library , lifted-base , mono-traversable , time + , process executable stackage-server if flag(library-only)