stackage-install 0.1.0.1 → 0.1.0.2
raw patch · 4 files changed
+49/−13 lines, 4 filesdep +http-typesdep ~http-client
Dependencies added: http-types
Dependency ranges changed: http-client
Files
- ChangeLog.md +4/−0
- README.md +12/−1
- Stackage/Install.hs +31/−11
- stackage-install.cabal +2/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+# 0.1.0.2++* Revert back to `cabal install --dry-run` [#2](https://github.com/fpco/stackage-install/issues/2)+ # 0.1.0.1 * Use `cabal fetch --dry-run`
README.md view
@@ -1,5 +1,7 @@ # stackage-install +[](https://travis-ci.org/fpco/stackage-install)+ `stackage-install` provides a wrapper around the `cabal install` command, which will download packages more securely. Initially, this means downloading over an HTTPS connection from FP Complete's Amazon S3 mirror of Hackage, though more@@ -11,7 +13,7 @@ foo` with [stackage-cli](http://github.com/fpco/stackage-cli) installed), which will perform the following steps: -1. Run `cabal fetch --dry-run ...` to get cabal's build plan+1. Run `cabal install --dry-run ...` to get cabal's build plan 2. Download the relevant packages from S3, and place them in the locations that `cabal-install` expects 3. Run `cabal install ...` @@ -31,6 +33,15 @@ in which case the second call may download some packages insecurely. I've opened [cabal issue #2566](https://github.com/haskell/cabal/issues/2566) about disabling downloading in cabal.++The output from `cabal install --dry-run` doesn't actually give us information+on which packages need to be downloaded, only the packages to be installed.+This will be different in the case of local packages. Unfortunately, `cabal+fetch` won't work for us either, since it accepts different arguments [see+#2](https://github.com/fpco/stackage-install/issues/2). The compromise we have+now is to just continue working in the presence of errors during download,+though a more robust solution would be to check if one of the arguments refers+to a local package. ## Why not fix cabal?
Stackage/Install.hs view
@@ -17,9 +17,12 @@ import qualified Data.Foldable as F import Data.Function (fix) import Data.List (isPrefixOf)-import Network.HTTP.Client (Manager, brRead, newManager,- parseUrl, responseBody, withResponse)+import Network.HTTP.Client (Manager, brRead, checkStatus,+ managerResponseTimeout, newManager,+ parseUrl, responseBody,+ responseStatus, withResponse) import Network.HTTP.Client.TLS (tlsManagerSettings)+import Network.HTTP.Types (statusCode) import System.Directory (createDirectoryIfMissing, doesFileExist, getAppUserDataDirectory, renameFile)@@ -36,7 +39,7 @@ install :: Settings -> [String] -> IO ExitCode install s args = do out <- readProcess (_cabalCommand s)- ("fetch":"--dry-run":if null args then ["."] else args)+ ("install":"--dry-run":if null args then ["."] else args) "" let pkgs = map toPair $ filter (not . toIgnore) $ lines out download s pkgs@@ -60,6 +63,7 @@ , _cabalCommand :: !FilePath , _downloadPrefix :: !String , _onDownload :: !(String -> IO ())+ , _onDownloadErr :: !(String -> IO ()) , _connections :: !Int } @@ -69,6 +73,8 @@ defaultSettings :: Settings defaultSettings = Settings { _getManager = newManager tlsManagerSettings+ { managerResponseTimeout = Just 90000000+ } , _cabalCommand = "cabal" , _downloadPrefix = "https://s3.amazonaws.com/hackage.fpcomplete.com/package/" , _onDownload = \s -> S8.hPut stdout $ S8.pack $ concat@@ -76,6 +82,11 @@ , s , "\n" ]+ , _onDownloadErr = \s -> S8.hPut stdout $ S8.pack $ concat+ [ "Error downloading "+ , s+ , ", if this is a local package, this message can be ignored\n"+ ] , _connections = 8 } @@ -97,14 +108,23 @@ _onDownload s pkg createDirectoryIfMissing True $ takeDirectory fp req <- parseUrl url- withResponse req man $ \res -> do- let tmp = fp <.> "tmp"- withBinaryFile tmp WriteMode $ \h -> fix $ \loop -> do- bs <- brRead $ responseBody res- unless (S.null bs) $ do- S.hPut h bs- loop- renameFile tmp fp+ let req' = req+ { checkStatus = \s x y ->+ if statusCode s `elem` [401, 403]+ -- See: https://github.com/fpco/stackage-install/issues/2+ then Nothing+ else checkStatus req s x y+ }+ withResponse req' man $ \res -> if statusCode (responseStatus res) == 200+ then do+ let tmp = fp <.> "tmp"+ withBinaryFile tmp WriteMode $ \h -> fix $ \loop -> do+ bs <- brRead $ responseBody res+ unless (S.null bs) $ do+ S.hPut h bs+ loop+ renameFile tmp fp+ else _onDownloadErr s pkg where pkg = concat [name, "-", version] targz = pkg ++ ".tar.gz"
stackage-install.cabal view
@@ -1,5 +1,5 @@ name: stackage-install-version: 0.1.0.1+version: 0.1.0.2 synopsis: Secure download of packages for cabal-install description: For more information, see <https://www.stackage.org/package/stackage-install> homepage: https://github.com/fpco/stackage-install@@ -23,6 +23,7 @@ , process >= 1 , async , stm+ , http-types default-language: Haskell2010 executable stackage-install