mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-02-10 10:07:29 +01:00
Allow for updated cabal files from Hackage.
This commit is contained in:
parent
e6213fc2b8
commit
a18f6a0317
@ -27,6 +27,8 @@ import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescriptio
|
|||||||
import Distribution.PackageDescription (GenericPackageDescription)
|
import Distribution.PackageDescription (GenericPackageDescription)
|
||||||
import Control.Exception (throw)
|
import Control.Exception (throw)
|
||||||
import Control.Monad.State.Strict (put, get, execStateT, MonadState)
|
import Control.Monad.State.Strict (put, get, execStateT, MonadState)
|
||||||
|
import Crypto.Hash.Conduit (sinkHash)
|
||||||
|
import Crypto.Hash (Digest, SHA256)
|
||||||
|
|
||||||
sinkUploadHistory :: Monad m => Consumer (Entity Uploaded) m UploadHistory
|
sinkUploadHistory :: Monad m => Consumer (Entity Uploaded) m UploadHistory
|
||||||
sinkUploadHistory =
|
sinkUploadHistory =
|
||||||
@ -69,9 +71,23 @@ loadCabalFiles uploadHistory0 = flip execStateT (UploadState uploadHistory0 [])
|
|||||||
Tar.NormalFile lbs _
|
Tar.NormalFile lbs _
|
||||||
| Just (name, version) <- parseFilePath (Tar.entryPath entry) -> do
|
| Just (name, version) <- parseFilePath (Tar.entryPath entry) -> do
|
||||||
let key = HackageCabal name version
|
let key = HackageCabal name version
|
||||||
exists <- storeExists key
|
-- It's not longer sufficient to simply check if the cabal
|
||||||
|
-- file exists, since Hackage now allows updating in place.
|
||||||
|
-- Instead, we have to check if it matches what we have
|
||||||
|
-- and, if not, update it.
|
||||||
store <- liftM getBlobStore ask
|
store <- liftM getBlobStore ask
|
||||||
unless exists $ withAcquire (storeWrite' store key) $ \sink ->
|
toStore <- withAcquire (storeRead' store key) $ \mcurr ->
|
||||||
|
case mcurr of
|
||||||
|
Nothing -> return True
|
||||||
|
Just curr -> do
|
||||||
|
-- Check if it matches. This is cheaper than
|
||||||
|
-- always writing, since it can take advantage
|
||||||
|
-- of the local filesystem cache and not go to
|
||||||
|
-- S3 each time.
|
||||||
|
currDigest <- curr $$ sinkHash
|
||||||
|
newDigest <- sourceLazy lbs $$ sinkHash
|
||||||
|
return $ currDigest /= (newDigest :: Digest SHA256)
|
||||||
|
when toStore $ withAcquire (storeWrite' store key) $ \sink ->
|
||||||
sourceLazy lbs $$ sink
|
sourceLazy lbs $$ sink
|
||||||
setUploadDate name version
|
setUploadDate name version
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user