[commit: packages/Cabal] ghc-head: Use a sum type as the return for downloadIndex. (a7fc45f)

git at git.haskell.org git at git.haskell.org
Mon Aug 26 23:25:58 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=a7fc45fb3151b4f329aefa10131ce0f514ce2c20

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

commit a7fc45fb3151b4f329aefa10131ce0f514ce2c20
Author: Thomas Dziedzic <gostrc at gmail.com>
Date:   Fri May 24 03:10:24 2013 +0000

    Use a sum type as the return for downloadIndex.


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

a7fc45fb3151b4f329aefa10131ce0f514ce2c20
 cabal-install/Distribution/Client/FetchUtils.hs |   12 +++++++-----
 cabal-install/Distribution/Client/Update.hs     |   14 ++++++++------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/cabal-install/Distribution/Client/FetchUtils.hs b/cabal-install/Distribution/Client/FetchUtils.hs
index 03a9139..8e6b118 100644
--- a/cabal-install/Distribution/Client/FetchUtils.hs
+++ b/cabal-install/Distribution/Client/FetchUtils.hs
@@ -23,6 +23,7 @@ module Distribution.Client.FetchUtils (
 
     -- * fetching other things
     downloadIndex,
+    DownloadResult(..),
   ) where
 
 import Distribution.Client.Types
@@ -50,6 +51,8 @@ import qualified System.FilePath.Posix as FilePath.Posix
 import Network.URI
          ( URI(uriPath) )
 
+data DownloadResult = FileAlreadyInCache | FileDownloaded FilePath deriving (Eq)
+
 -- ------------------------------------------------------------
 -- * Actually fetch things
 -- ------------------------------------------------------------
@@ -141,10 +144,7 @@ fetchRepoTarball verbosity repo pkgid = do
 
 -- | Downloads an index file to [config-dir/packages/serv-id].
 --
-downloadIndex :: Verbosity
-              -> RemoteRepo
-              -> FilePath
-              -> IO (FilePath, Bool) -- ^ Path and if the file is cached.
+downloadIndex :: Verbosity -> RemoteRepo -> FilePath -> IO DownloadResult
 downloadIndex verbosity repo cacheDir = do
   let uri = (remoteRepoURI repo) {
               uriPath = uriPath (remoteRepoURI repo)
@@ -153,7 +153,9 @@ downloadIndex verbosity repo cacheDir = do
       path = cacheDir </> "00-index" <.> "tar.gz"
   createDirectoryIfMissing True cacheDir
   isCached <- downloadURI verbosity uri path
-  return (path, isCached)
+  if isCached
+    then return FileAlreadyInCache
+    else return (FileDownloaded path)
 
 
 -- ------------------------------------------------------------
diff --git a/cabal-install/Distribution/Client/Update.hs b/cabal-install/Distribution/Client/Update.hs
index b5a15f4..7b3fa5d 100644
--- a/cabal-install/Distribution/Client/Update.hs
+++ b/cabal-install/Distribution/Client/Update.hs
@@ -17,7 +17,7 @@ module Distribution.Client.Update
 import Distribution.Client.Types
          ( Repo(..), RemoteRepo(..), LocalRepo(..), SourcePackageDb(..) )
 import Distribution.Client.FetchUtils
-         ( downloadIndex )
+         ( downloadIndex, DownloadResult(..) )
 import qualified Distribution.Client.PackageIndex as PackageIndex
 import Distribution.Client.IndexUtils
          ( getSourcePackages, updateRepoIndexCache )
@@ -55,11 +55,13 @@ updateRepo verbosity repo = case repoKind repo of
   Left remoteRepo -> do
     notice verbosity $ "Downloading the latest package list from "
                     ++ remoteRepoName remoteRepo
-    (indexPath, isCached) <- downloadIndex verbosity remoteRepo (repoLocalDir repo)
-    unless isCached $ do
-      writeFileAtomic (dropExtension indexPath) . maybeDecompress
-                                              =<< BS.readFile indexPath
-      updateRepoIndexCache verbosity repo
+    downloadResult <- downloadIndex verbosity remoteRepo (repoLocalDir repo)
+    case downloadResult of
+      FileAlreadyInCache -> return ()
+      FileDownloaded indexPath -> do
+        writeFileAtomic (dropExtension indexPath) . maybeDecompress
+                                                =<< BS.readFile indexPath
+        updateRepoIndexCache verbosity repo
 
 checkForSelfUpgrade :: Verbosity -> [Repo] -> IO ()
 checkForSelfUpgrade verbosity repos = do





More information about the ghc-commits mailing list