From c5f51c26171593a6dae2ca7df86011161d50c7fe Mon Sep 17 00:00:00 2001
From: Mikhail Glushenkov <mikhail.glushenkov@gmail.com>
Date: Fri, 24 Oct 2014 02:32:02 +0200
Subject: [PATCH] Force-update the cache in 'add-source'/'remove-source'.

Fixes #2060.
---
 cabal-install/Distribution/Client/IndexUtils.hs    | 1 +
 cabal-install/Distribution/Client/Sandbox/Index.hs | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/cabal-install/Distribution/Client/IndexUtils.hs b/cabal-install/Distribution/Client/IndexUtils.hs
index 5e6a404ee6..b9fe2e5207 100644
--- a/cabal-install/Distribution/Client/IndexUtils.hs
+++ b/cabal-install/Distribution/Client/IndexUtils.hs
@@ -21,6 +21,7 @@ module Distribution.Client.IndexUtils (
   parsePackageIndex,
   readRepoIndex,
   updateRepoIndexCache,
+  updatePackageIndexCacheFile,
 
   BuildTreeRefType(..), refTypeFromTypeCode, typeCodeFromRefType
   ) where
diff --git a/cabal-install/Distribution/Client/Sandbox/Index.hs b/cabal-install/Distribution/Client/Sandbox/Index.hs
index 2ff84b5f76..b3c1f503b5 100644
--- a/cabal-install/Distribution/Client/Sandbox/Index.hs
+++ b/cabal-install/Distribution/Client/Sandbox/Index.hs
@@ -22,6 +22,7 @@ import qualified Distribution.Client.Tar as Tar
 import Distribution.Client.IndexUtils ( BuildTreeRefType(..)
                                       , refTypeFromTypeCode
                                       , typeCodeFromRefType
+                                      , updatePackageIndexCacheFile
                                       , getSourcePackagesStrict )
 import Distribution.Client.PackageIndex ( allPackages )
 import Distribution.Client.Types ( Repo(..), LocalRepo(..)
@@ -43,7 +44,8 @@ import Data.Maybe                ( catMaybes )
 import System.Directory          ( createDirectoryIfMissing,
                                    doesDirectoryExist, doesFileExist,
                                    renameFile )
-import System.FilePath           ( (</>), (<.>), takeDirectory, takeExtension )
+import System.FilePath           ( (</>), (<.>), takeDirectory, takeExtension
+                                 , replaceExtension )
 import System.IO                 ( IOMode(..), SeekMode(..)
                                  , hSeek, withBinaryFile )
 
@@ -150,6 +152,8 @@ addBuildTreeRefs verbosity path l' refType = do
       hSeek h AbsoluteSeek (fromIntegral offset)
       BS.hPut h (Tar.write entries)
       debug verbosity $ "Successfully appended to '" ++ path ++ "'"
+    updatePackageIndexCacheFile verbosity path
+      (path `replaceExtension` "cache")
 
 -- | Remove given local build tree references from the index.
 removeBuildTreeRefs :: Verbosity -> FilePath -> [FilePath] -> IO [FilePath]
@@ -164,10 +168,10 @@ removeBuildTreeRefs verbosity path l' = do
   -- much smaller.
   BS.writeFile tmpFile . Tar.writeEntries . Tar.filterEntries (p l) . Tar.read
     =<< BS.readFile path
-  -- This invalidates the cache, so we don't have to update it explicitly.
   renameFile tmpFile path
   debug verbosity $ "Successfully renamed '" ++ tmpFile
     ++ "' to '" ++ path ++ "'"
+  updatePackageIndexCacheFile verbosity path (path `replaceExtension` "cache")
   -- FIXME: return only the refs that vere actually removed.
   return l
     where
-- 
GitLab