[commit: packages/Cabal] ghc-head: Use DownloadResult in downloadURI. (917cc20)

git at git.haskell.org git at git.haskell.org
Mon Aug 26 23:26:00 CEST 2013


Repository : ssh://git@git.haskell.org/Cabal

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=917cc20f0a4227ffa42eebccf61e27f9e2796b1d

>---------------------------------------------------------------

commit 917cc20f0a4227ffa42eebccf61e27f9e2796b1d
Author: Thomas Dziedzic <gostrc at gmail.com>
Date:   Fri May 24 03:22:25 2013 +0000

    Use DownloadResult in downloadURI.


>---------------------------------------------------------------

917cc20f0a4227ffa42eebccf61e27f9e2796b1d
 cabal-install/Distribution/Client/FetchUtils.hs |   10 ++--------
 cabal-install/Distribution/Client/HttpUtils.hs  |   15 +++++++++------
 cabal-install/Distribution/Client/Update.hs     |    4 +++-
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/cabal-install/Distribution/Client/FetchUtils.hs b/cabal-install/Distribution/Client/FetchUtils.hs
index 8e6b118..97920bb 100644
--- a/cabal-install/Distribution/Client/FetchUtils.hs
+++ b/cabal-install/Distribution/Client/FetchUtils.hs
@@ -23,12 +23,11 @@ module Distribution.Client.FetchUtils (
 
     -- * fetching other things
     downloadIndex,
-    DownloadResult(..),
   ) where
 
 import Distribution.Client.Types
 import Distribution.Client.HttpUtils
-         ( downloadURI, isOldHackageURI )
+         ( downloadURI, isOldHackageURI, DownloadResult(..) )
 
 import Distribution.Package
          ( PackageId, packageName, packageVersion )
@@ -51,8 +50,6 @@ import qualified System.FilePath.Posix as FilePath.Posix
 import Network.URI
          ( URI(uriPath) )
 
-data DownloadResult = FileAlreadyInCache | FileDownloaded FilePath deriving (Eq)
-
 -- ------------------------------------------------------------
 -- * Actually fetch things
 -- ------------------------------------------------------------
@@ -152,10 +149,7 @@ downloadIndex verbosity repo cacheDir = do
             }
       path = cacheDir </> "00-index" <.> "tar.gz"
   createDirectoryIfMissing True cacheDir
-  isCached <- downloadURI verbosity uri path
-  if isCached
-    then return FileAlreadyInCache
-    else return (FileDownloaded path)
+  downloadURI verbosity uri path
 
 
 -- ------------------------------------------------------------
diff --git a/cabal-install/Distribution/Client/HttpUtils.hs b/cabal-install/Distribution/Client/HttpUtils.hs
index 6446cd2..989e754 100644
--- a/cabal-install/Distribution/Client/HttpUtils.hs
+++ b/cabal-install/Distribution/Client/HttpUtils.hs
@@ -2,6 +2,7 @@
 -- | Separate module for HTTP actions, using a proxy server if one exists 
 -----------------------------------------------------------------------------
 module Distribution.Client.HttpUtils (
+    DownloadResult(..),
     downloadURI,
     getHTTP,
     cabalBrowse,
@@ -40,6 +41,8 @@ import System.FilePath
 import System.Directory
          ( doesFileExist )
 
+data DownloadResult = FileAlreadyInCache | FileDownloaded FilePath deriving (Eq)
+
 -- Trime
 trim :: String -> String
 trim = f . f
@@ -92,11 +95,11 @@ cabalBrowse verbosity auth act = do
 downloadURI :: Verbosity
             -> URI      -- ^ What to download
             -> FilePath -- ^ Where to put it
-            -> IO Bool  -- ^ If we have a cached version.
+            -> IO DownloadResult
 downloadURI verbosity uri path | uriScheme uri == "file:" = do
   copyFileVerbose verbosity (uriPath uri) path
-  return False
-  -- Can we store the hash of the file so we can safely return True when the
+  return (FileDownloaded path)
+  -- Can we store the hash of the file so we can safely return path when the
   -- hash matches to avoid unnecessary computation?
 downloadURI verbosity uri path = do
   let etagPath = path <.> "etag"
@@ -132,11 +135,11 @@ downloadURI verbosity uri path = do
       (2,0,0) -> do
         info verbosity ("Downloaded to " ++ path)
         writeFileAtomic path $ rspBody rsp
-        return False
+        return (FileDownloaded path)
       (3,0,4) -> do
         notice verbosity "Skipping download: Local and remote files match."
-        return True
-      (_,_,_) -> return False
+        return FileAlreadyInCache
+      (_,_,_) -> return (FileDownloaded path)
       --FIXME: check the content-length header matches the body length.
       --TODO: stream the download into the file rather than buffering the whole
       --      thing in memory.
diff --git a/cabal-install/Distribution/Client/Update.hs b/cabal-install/Distribution/Client/Update.hs
index 7b3fa5d..a678c23 100644
--- a/cabal-install/Distribution/Client/Update.hs
+++ b/cabal-install/Distribution/Client/Update.hs
@@ -16,8 +16,10 @@ module Distribution.Client.Update
 
 import Distribution.Client.Types
          ( Repo(..), RemoteRepo(..), LocalRepo(..), SourcePackageDb(..) )
+import Distribution.Client.HttpUtils
+         ( DownloadResult(..) )
 import Distribution.Client.FetchUtils
-         ( downloadIndex, DownloadResult(..) )
+         ( downloadIndex )
 import qualified Distribution.Client.PackageIndex as PackageIndex
 import Distribution.Client.IndexUtils
          ( getSourcePackages, updateRepoIndexCache )





More information about the ghc-commits mailing list