1
- {-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards, ViewPatterns, TupleSections #-}
1
+ {-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards, ViewPatterns,
2
+ TupleSections #-}
2
3
3
4
-- | cabal-install CLI command: update
4
5
--
@@ -7,6 +8,8 @@ module Distribution.Client.CmdUpdate (
7
8
updateAction ,
8
9
) where
9
10
11
+ import Distribution.Client.Compat.Directory
12
+ ( setModificationTime )
10
13
import Distribution.Client.ProjectOrchestration
11
14
import Distribution.Client.ProjectConfig
12
15
( ProjectConfig (.. )
@@ -20,8 +23,9 @@ import Distribution.Client.FetchUtils
20
23
import Distribution.Client.JobControl
21
24
( newParallelJobControl , spawnJob , collectJob )
22
25
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 (.. ) )
25
29
import Distribution.Simple.Setup
26
30
( HaddockFlags , fromFlagOrDefault )
27
31
import Distribution.Simple.Utils
@@ -31,26 +35,27 @@ import Distribution.Verbosity
31
35
import Distribution.Client.IndexUtils.Timestamp
32
36
import Distribution.Client.IndexUtils
33
37
( updateRepoIndexCache , Index (.. ), writeIndexTimestamp
34
- , currentIndexTimestamp )
38
+ , currentIndexTimestamp , indexBaseName )
35
39
import Distribution.Text
36
40
( Text (.. ), display , simpleParse )
37
41
38
42
import Data.Maybe (fromJust )
39
43
import qualified Distribution.Compat.ReadP as ReadP
40
- import qualified Text.PrettyPrint as Disp
44
+ import qualified Text.PrettyPrint as Disp
41
45
42
46
import Control.Monad (unless , when )
43
47
import qualified Data.ByteString.Lazy as BS
44
48
import Distribution.Client.GZipUtils (maybeDecompress )
45
- import System.FilePath (dropExtension )
49
+ import System.FilePath ((<.>) , dropExtension )
46
50
import Data.Time (getCurrentTime )
47
51
import Distribution.Simple.Command
48
52
( CommandUI (.. ), usageAlternatives )
49
53
import qualified Distribution.Client.Setup as Client
50
54
51
55
import qualified Hackage.Security.Client as Sec
52
56
53
- updateCommand :: CommandUI (ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags )
57
+ updateCommand :: CommandUI ( ConfigFlags , ConfigExFlags
58
+ , InstallFlags , HaddockFlags )
54
59
updateCommand = Client. installCommand {
55
60
commandName = " new-update" ,
56
61
commandSynopsis = " Updates list of known packages." ,
@@ -102,39 +107,45 @@ instance Text UpdateRequest where
102
107
103
108
updateAction :: (ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags )
104
109
-> [String ] -> GlobalFlags -> IO ()
105
- updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
110
+ updateAction (applyFlagDefaults -> ( configFlags, configExFlags
111
+ , installFlags, haddockFlags ))
106
112
extraArgs globalFlags = do
107
113
108
114
ProjectBaseContext {
109
115
projectConfig
110
116
} <- establishProjectBaseContext verbosity cliConfig
111
117
112
- projectConfigWithSolverRepoContext verbosity (projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
118
+ projectConfigWithSolverRepoContext verbosity
119
+ (projectConfigShared projectConfig) (projectConfigBuildOnly projectConfig)
113
120
$ \ repoCtxt -> do
114
121
let repos = filter isRepoRemote $ repoContextRepos repoCtxt
115
122
repoName = remoteRepoName . repoRemote
116
123
parseArg :: String -> IO UpdateRequest
117
124
parseArg s = case simpleParse s of
118
125
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 ++ " \" "
120
128
updateRepoRequests <- mapM parseArg extraArgs
121
129
122
130
unless (null updateRepoRequests) $ do
123
131
let remoteRepoNames = map repoName repos
124
132
unknownRepos = [r | (UpdateRequest r _) <- updateRepoRequests
125
133
, not (r `elem` remoteRepoNames)]
126
134
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
129
139
130
140
let reposToUpdate :: [(Repo , IndexState )]
131
141
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.
134
144
[] -> map (,IndexStateHead ) repos
135
145
updateRequests -> let repoMap = [(repoName r, r) | r <- repos]
136
146
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 ]
138
149
139
150
case reposToUpdate of
140
151
[] -> return ()
@@ -146,7 +157,8 @@ updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, ha
146
157
: map ((" - " ++ ) . repoName . fst ) reposToUpdate
147
158
148
159
jobCtrl <- newParallelJobControl (length reposToUpdate)
149
- mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt) reposToUpdate
160
+ mapM_ (spawnJob jobCtrl . updateRepo verbosity defaultUpdateFlags repoCtxt)
161
+ reposToUpdate
150
162
mapM_ (\ _ -> collectJob jobCtrl) reposToUpdate
151
163
152
164
where
@@ -155,15 +167,19 @@ updateAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, ha
155
167
globalFlags configFlags configExFlags
156
168
installFlags haddockFlags
157
169
158
- updateRepo :: Verbosity -> UpdateFlags -> RepoContext -> (Repo , IndexState ) -> IO ()
170
+ updateRepo :: Verbosity -> UpdateFlags -> RepoContext -> (Repo , IndexState )
171
+ -> IO ()
159
172
updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
160
173
transport <- repoContextGetTransport repoCtxt
161
174
case repo of
162
175
RepoLocal {.. } -> return ()
163
176
RepoRemote {.. } -> do
164
- downloadResult <- downloadIndex transport verbosity repoRemote repoLocalDir
177
+ downloadResult <- downloadIndex transport verbosity
178
+ repoRemote repoLocalDir
165
179
case downloadResult of
166
- FileAlreadyInCache -> return ()
180
+ FileAlreadyInCache ->
181
+ setModificationTime (indexBaseName repo <.> " tar" )
182
+ =<< getCurrentTime
167
183
FileDownloaded indexPath -> do
168
184
writeFileAtomic (dropExtension indexPath) . maybeDecompress
169
185
=<< BS. readFile indexPath
@@ -183,7 +199,8 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
183
199
-- (If all access to the cache goes through hackage-security this can go)
184
200
case updated of
185
201
Sec. NoUpdates ->
186
- return ()
202
+ setModificationTime (indexBaseName repo <.> " tar" )
203
+ =<< getCurrentTime
187
204
Sec. HasUpdates ->
188
205
updateRepoIndexCache verbosity index
189
206
-- TODO: This will print multiple times if there are multiple
@@ -192,5 +209,5 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
192
209
when (current_ts /= nullTimestamp) $
193
210
noticeNoWrap verbosity $
194
211
" 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