Skip to content

Commit d9a5c08

Browse files
authored
Merge pull request #5090 from 23Skidoo/issue-4444-new-update
Port #4950 to new-update.
2 parents 67b443d + 50be934 commit d9a5c08

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

cabal-install/Distribution/Client/CmdUpdate.hs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards, ViewPatterns, TupleSections #-}
1+
{-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards, ViewPatterns,
2+
TupleSections #-}
23

34
-- | cabal-install CLI command: update
45
--
@@ -7,6 +8,8 @@ module Distribution.Client.CmdUpdate (
78
updateAction,
89
) where
910

11+
import Distribution.Client.Compat.Directory
12+
( setModificationTime )
1013
import Distribution.Client.ProjectOrchestration
1114
import Distribution.Client.ProjectConfig
1215
( ProjectConfig(..)
@@ -20,8 +23,9 @@ import Distribution.Client.FetchUtils
2023
import Distribution.Client.JobControl
2124
( newParallelJobControl, spawnJob, collectJob )
2225
import Distribution.Client.Setup
23-
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags, UpdateFlags
24-
, applyFlagDefaults, defaultUpdateFlags, RepoContext(..) )
26+
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
27+
, UpdateFlags, applyFlagDefaults, defaultUpdateFlags
28+
, RepoContext(..) )
2529
import Distribution.Simple.Setup
2630
( HaddockFlags, fromFlagOrDefault )
2731
import Distribution.Simple.Utils
@@ -31,26 +35,27 @@ import Distribution.Verbosity
3135
import Distribution.Client.IndexUtils.Timestamp
3236
import Distribution.Client.IndexUtils
3337
( updateRepoIndexCache, Index(..), writeIndexTimestamp
34-
, currentIndexTimestamp )
38+
, currentIndexTimestamp, indexBaseName )
3539
import Distribution.Text
3640
( Text(..), display, simpleParse )
3741

3842
import Data.Maybe (fromJust)
3943
import qualified Distribution.Compat.ReadP as ReadP
40-
import qualified Text.PrettyPrint as Disp
44+
import qualified Text.PrettyPrint as Disp
4145

4246
import Control.Monad (unless, when)
4347
import qualified Data.ByteString.Lazy as BS
4448
import Distribution.Client.GZipUtils (maybeDecompress)
45-
import System.FilePath (dropExtension)
49+
import System.FilePath ((<.>), dropExtension)
4650
import Data.Time (getCurrentTime)
4751
import Distribution.Simple.Command
4852
( CommandUI(..), usageAlternatives )
4953
import qualified Distribution.Client.Setup as Client
5054

5155
import qualified Hackage.Security.Client as Sec
5256

53-
updateCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
57+
updateCommand :: CommandUI ( ConfigFlags, ConfigExFlags
58+
, InstallFlags, HaddockFlags )
5459
updateCommand = Client.installCommand {
5560
commandName = "new-update",
5661
commandSynopsis = "Updates list of known packages.",
@@ -102,39 +107,45 @@ instance Text UpdateRequest where
102107

103108
updateAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
104109
-> [String] -> GlobalFlags -> IO ()
105-
updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
110+
updateAction (applyFlagDefaults -> ( configFlags, configExFlags
111+
, installFlags, haddockFlags ))
106112
extraArgs globalFlags = do
107113

108114
ProjectBaseContext {
109115
projectConfig
110116
} <- establishProjectBaseContext verbosity cliConfig
111117

112-
projectConfigWithSolverRepoContext verbosity (projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
118+
projectConfigWithSolverRepoContext verbosity
119+
(projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
113120
$ \repoCtxt -> do
114121
let repos = filter isRepoRemote $ repoContextRepos repoCtxt
115122
repoName = remoteRepoName . repoRemote
116123
parseArg :: String -> IO UpdateRequest
117124
parseArg s = case simpleParse s of
118125
Just r -> return r
119-
Nothing -> die' verbosity $ "'new-update' unable to parse repo: \"" ++ s ++ "\""
126+
Nothing -> die' verbosity $
127+
"'new-update' unable to parse repo: \"" ++ s ++ "\""
120128
updateRepoRequests <- mapM parseArg extraArgs
121129

122130
unless (null updateRepoRequests) $ do
123131
let remoteRepoNames = map repoName repos
124132
unknownRepos = [r | (UpdateRequest r _) <- updateRepoRequests
125133
, not (r `elem` remoteRepoNames)]
126134
unless (null unknownRepos) $
127-
die' verbosity $ "'new-update' repo(s): \"" ++ intercalate "\", \"" unknownRepos
128-
++ "\" can not be found in known remote repo(s): " ++ intercalate ", " remoteRepoNames
135+
die' verbosity $ "'new-update' repo(s): \""
136+
++ intercalate "\", \"" unknownRepos
137+
++ "\" can not be found in known remote repo(s): "
138+
++ intercalate ", " remoteRepoNames
129139

130140
let reposToUpdate :: [(Repo, IndexState)]
131141
reposToUpdate = case updateRepoRequests of
132-
-- if we are not given any speicifc repository. Update all repositories to
133-
-- HEAD.
142+
-- If we are not given any specific repository, update all
143+
-- repositories to HEAD.
134144
[] -> map (,IndexStateHead) repos
135145
updateRequests -> let repoMap = [(repoName r, r) | r <- repos]
136146
lookup' k = fromJust (lookup k repoMap)
137-
in [(lookup' name, state) | (UpdateRequest name state) <- updateRequests]
147+
in [ (lookup' name, state)
148+
| (UpdateRequest name state) <- updateRequests ]
138149

139150
case reposToUpdate of
140151
[] -> return ()
@@ -146,7 +157,8 @@ updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, ha
146157
: map (("- " ++) . repoName . fst) reposToUpdate
147158

148159
jobCtrl <- newParallelJobControl (length reposToUpdate)
149-
mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) reposToUpdate
160+
mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt)
161+
reposToUpdate
150162
mapM_ (\_ -> collectJob jobCtrl) reposToUpdate
151163

152164
where
@@ -155,15 +167,19 @@ updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, ha
155167
globalFlags configFlags configExFlags
156168
installFlags haddockFlags
157169

158-
updateRepo :: Verbosity -> UpdateFlags -> RepoContext -> (Repo, IndexState) -> IO ()
170+
updateRepo :: Verbosity -> UpdateFlags -> RepoContext -> (Repo, IndexState)
171+
-> IO ()
159172
updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
160173
transport <- repoContextGetTransport repoCtxt
161174
case repo of
162175
RepoLocal{..} -> return ()
163176
RepoRemote{..} -> do
164-
downloadResult <- downloadIndex transport verbosity repoRemote repoLocalDir
177+
downloadResult <- downloadIndex transport verbosity
178+
repoRemote repoLocalDir
165179
case downloadResult of
166-
FileAlreadyInCache -> return ()
180+
FileAlreadyInCache ->
181+
setModificationTime (indexBaseName repo <.> "tar")
182+
=<< getCurrentTime
167183
FileDownloaded indexPath -> do
168184
writeFileAtomic (dropExtension indexPath) . maybeDecompress
169185
=<< BS.readFile indexPath
@@ -183,7 +199,8 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
183199
-- (If all access to the cache goes through hackage-security this can go)
184200
case updated of
185201
Sec.NoUpdates ->
186-
return ()
202+
setModificationTime (indexBaseName repo <.> "tar")
203+
=<< getCurrentTime
187204
Sec.HasUpdates ->
188205
updateRepoIndexCache verbosity index
189206
-- TODO: This will print multiple times if there are multiple
@@ -192,5 +209,5 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
192209
when (current_ts /= nullTimestamp) $
193210
noticeNoWrap verbosity $
194211
"To revert to previous state run:\n" ++
195-
" cabal new-update '" ++ remoteRepoName (repoRemote repo) ++ "," ++ display current_ts ++ "'\n"
196-
212+
" cabal new-update '" ++ remoteRepoName (repoRemote repo)
213+
++ "," ++ display current_ts ++ "'\n"

0 commit comments

Comments
 (0)