From 06dca68b73ccbc385f2ca99ec0606c38bf805415 Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Wed, 30 Dec 2015 16:33:09 +0000 Subject: [PATCH 1/2] #1418, if git fetch fails wipe the directory and try again from scratch --- src/Stack/PackageIndex.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Stack/PackageIndex.hs b/src/Stack/PackageIndex.hs index 92fcfdfb4e..6fe4b7e2d7 100644 --- a/src/Stack/PackageIndex.hs +++ b/src/Stack/PackageIndex.hs @@ -13,6 +13,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE ScopedTypeVariables #-} -- | Dealing with the 00-index file and all its cabal files. module Stack.PackageIndex @@ -64,7 +65,8 @@ import Stack.Types.StackT import System.FilePath (takeBaseName, (<.>)) import System.IO (IOMode (ReadMode, WriteMode), withBinaryFile) -import System.Process.Read (readInNull, EnvOverride, doesExecutableExist) +import System.Process.Read (readInNull, readProcessNull, ReadProcessException(..), + EnvOverride, doesExecutableExist) -- | Populate the package index caches and return them. populateCache @@ -243,7 +245,13 @@ updateIndexGit menv indexName' index gitUrl = do unless repoExists (readInNull suDir "git" menv cloneArgs Nothing) $logSticky "Fetching package index ..." - readInNull acfDir "git" menv ["fetch","--tags","--depth=1"] Nothing + readProcessNull (Just acfDir) menv "git" ["fetch","--tags","--depth=1"] `C.catch` \(_ :: ReadProcessException) -> do + -- we failed, so wipe the directory and try again, see #1418 + $logStickyDone "Failed to fetch package index, retrying." + removeTree acfDir + readInNull suDir "git" menv cloneArgs Nothing + $logSticky "Fetching package index ..." + readInNull acfDir "git" menv ["fetch","--tags","--depth=1"] Nothing $logStickyDone "Fetched package index." removeFileIfExists tarFile when (indexGpgVerify index) From 71fa0568363f7566f6ad088c450d4cac3fa1b57b Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Thu, 31 Dec 2015 18:31:51 +0000 Subject: [PATCH 2/2] Also log the error message when git updating fails --- src/Stack/PackageIndex.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Stack/PackageIndex.hs b/src/Stack/PackageIndex.hs index 6fe4b7e2d7..2b7075a793 100644 --- a/src/Stack/PackageIndex.hs +++ b/src/Stack/PackageIndex.hs @@ -245,8 +245,9 @@ updateIndexGit menv indexName' index gitUrl = do unless repoExists (readInNull suDir "git" menv cloneArgs Nothing) $logSticky "Fetching package index ..." - readProcessNull (Just acfDir) menv "git" ["fetch","--tags","--depth=1"] `C.catch` \(_ :: ReadProcessException) -> do + readProcessNull (Just acfDir) menv "git" ["fetch","--tags","--depth=1"] `C.catch` \(ex :: ReadProcessException) -> do -- we failed, so wipe the directory and try again, see #1418 + $logWarn (T.pack (show ex)) $logStickyDone "Failed to fetch package index, retrying." removeTree acfDir readInNull suDir "git" menv cloneArgs Nothing