@@ -79,7 +79,8 @@ import Distribution.Types.PackageName (PackageName)
79
79
import Distribution.Version
80
80
( Version , VersionRange , mkVersion , intersectVersionRanges )
81
81
import Distribution.Simple.Utils
82
- ( die' , warn , info , createDirectoryIfMissingVerbose , fromUTF8LBS )
82
+ ( die' , dieNoVerbosity , warn , info
83
+ , createDirectoryIfMissingVerbose , fromUTF8LBS )
83
84
import Distribution.Client.Setup
84
85
( RepoContext (.. ) )
85
86
@@ -106,7 +107,7 @@ import Distribution.Client.Utils ( byteStringToFilePath
106
107
, tryFindAddSourcePackageDesc )
107
108
import Distribution.Utils.Structured (Structured (.. ), nominalStructure , structuredEncodeFile , structuredDecodeFileOrFail )
108
109
import Distribution.Compat.Time (getFileAge , getModTime )
109
- import System.Directory (doesFileExist , doesDirectoryExist )
110
+ import System.Directory (doesFileExist , doesDirectoryExist , getModificationTime )
110
111
import System.FilePath
111
112
( (</>) , (<.>) , takeFileName , takeExtension , replaceExtension , splitDirectories , normalise , takeDirectory )
112
113
import qualified System.FilePath.Posix as FilePath.Posix
@@ -275,17 +276,12 @@ getSourcePackagesAtIndexState verbosity repoCtxt mb_idxState mb_activeRepos = do
275
276
return ()
276
277
IndexStateTime ts0 -> do
277
278
when (isiMaxTime isi /= ts0) $
278
- if ts0 > isiMaxTime isi
279
- then warn verbosity $
280
- " Requested index-state " ++ prettyShow ts0
281
- ++ " is newer than '" ++ unRepoName rname ++ " '!"
282
- ++ " Falling back to older state ("
283
- ++ prettyShow (isiMaxTime isi) ++ " )."
284
- else info verbosity $
285
- " Requested index-state " ++ prettyShow ts0
286
- ++ " does not exist in '" ++ unRepoName rname ++ " '!"
287
- ++ " Falling back to older state ("
288
- ++ prettyShow (isiMaxTime isi) ++ " )."
279
+ info verbosity $
280
+ " There is no index-state for '"
281
+ ++ unRepoName rname ++ " ' exactly at the requested timestamp ("
282
+ ++ prettyShow ts0 ++ " ). Falling back to the previous index-state that exists: "
283
+ ++ prettyShow (isiMaxTime isi)
284
+
289
285
info verbosity (" index-state(" ++ unRepoName rname ++ " ) = " ++
290
286
prettyShow (isiMaxTime isi) ++ " (HEAD = " ++
291
287
prettyShow (isiHeadTime isi) ++ " )" )
@@ -364,7 +360,11 @@ readRepoIndex :: Verbosity -> RepoContext -> Repo -> RepoIndexState
364
360
-> IO (PackageIndex UnresolvedSourcePackage , [Dependency ], IndexStateInfo )
365
361
readRepoIndex verbosity repoCtxt repo idxState =
366
362
handleNotFound $ do
367
- when (isRepoRemote repo) $ warnIfIndexIsOld =<< getIndexFileAge repo
363
+ when (isRepoRemote repo) $ do
364
+ dt <- getIndexFileAge repo
365
+ ts <- getIndexTimestamp repo
366
+ warnIfIndexIsOld dt
367
+ dieIfRequestedIdxIsNewer ts
368
368
-- note that if this step fails due to a bad repo cache, the the procedure can still succeed by reading from the existing cache, which is updated regardless.
369
369
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo) `catchIO`
370
370
(\ e -> warn verbosity $ " unable to update the repo index cache -- " ++ displayException e)
@@ -406,6 +406,16 @@ readRepoIndex verbosity repoCtxt repo idxState =
406
406
RepoSecure {.. } -> warn verbosity $ errOutdatedPackageList repoRemote dt
407
407
RepoLocalNoIndex {} -> return ()
408
408
409
+ dieIfRequestedIdxIsNewer ts = do
410
+ case idxState of
411
+ IndexStateHead -> return ()
412
+ IndexStateTime ts0
413
+ | ts < ts0 -> die' verbosity $
414
+ " Latest known index-state for '" ++ unRepoName (repoName repo) ++ " ' ("
415
+ ++ prettyShow ts ++ " ) is older than the requested index-state ("
416
+ ++ prettyShow ts0 ++ " ).\n Run 'cabal update' or set the index-state to a value at or before " ++ prettyShow ts ++ " ."
417
+ | otherwise -> return ()
418
+
409
419
errMissingPackageList repoRemote =
410
420
" The package list for '" ++ unRepoName (remoteRepoName repoRemote)
411
421
++ " ' does not exist. Run 'cabal update' to download it."
@@ -418,6 +428,14 @@ readRepoIndex verbosity repoCtxt repo idxState =
418
428
getIndexFileAge :: Repo -> IO Double
419
429
getIndexFileAge repo = getFileAge $ indexBaseName repo <.> " tar"
420
430
431
+ -- | Get the timestamp of a file.
432
+ getIndexTimestamp :: Repo -> IO Timestamp
433
+ getIndexTimestamp repo = do
434
+ mb_ts <- utcTimeToTimestamp <$> getModificationTime (indexBaseName repo <.> " tar" )
435
+ case mb_ts of
436
+ Nothing -> dieNoVerbosity " Can't convert modification time to UTC timestamp"
437
+ Just ts -> pure ts
438
+
421
439
-- | A set of files (or directories) that can be monitored to detect when
422
440
-- there might have been a change in the source packages.
423
441
--
0 commit comments