Commit dc889b17 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by GitHub
Browse files

Store secure repo index data as 01-index.* (#3862)

"Secure" cabal repositories use a new extended & incremental
`01-index.tar`. In order to avoid issues resulting from clobbering
new/old-style index data, we save them locally to different names.

With this patch, secure repos generate/update the files below on `cabal update`

- `01-index.cache`
- `01-index.tar`
- `01-index.tar.gz`
- `01-index.tar.idx`
- `mirrors.json`
- `root.json`
- `snapshot.json`
- `timestamp.json`

...while the legacy codepaths for non-secure repos operate on the files

- `00-index.cache`
- `00-index.tar`
- `00-index.tar.gz`
- `00-index.tar.gz.etag`

This way the old/new codepaths don't interfere with each other anymore.

Note: The format of `01-index.cache` file will be extended by the upcoming `--index-state` feature

This trivially fixes #3854
parent 48d9077b
......@@ -250,8 +250,15 @@ initSecureRepo verbosity httpLib RemoteRepo{..} cachePath = \callback -> do
cache :: Sec.Cache
cache = Sec.Cache {
cacheRoot = cachePath
, cacheLayout = Sec.cabalCacheLayout
, cacheLayout = Sec.cabalCacheLayout {
Sec.cacheLayoutIndexTar = cacheFn "01-index.tar"
, Sec.cacheLayoutIndexIdx = cacheFn "01-index.tar.idx"
, Sec.cacheLayoutIndexTarGz = cacheFn "01-index.tar.gz"
}
}
cacheFn :: FilePath -> Sec.CachePath
cacheFn = Sec.rootPath . Sec.fragment
-- We display any TUF progress only in verbose mode, including any transient
-- verification errors. If verification fails, then the final exception that
......
......@@ -90,7 +90,7 @@ import Distribution.Compat.Exception (catchIO)
import Distribution.Compat.Time (getFileAge, getModTime)
import System.Directory (doesFileExist, doesDirectoryExist)
import System.FilePath
( (</>), takeExtension, replaceExtension, splitDirectories, normalise )
( (</>), (<.>), takeExtension, replaceExtension, splitDirectories, normalise )
import System.FilePath.Posix as FilePath.Posix
( takeFileName )
import System.IO
......@@ -109,6 +109,23 @@ getInstalledPackages verbosity comp packageDbs progdb =
where
verbosity' = lessVerbose verbosity
-- | Get filename base (i.e. without file extension) for index-related files
--
-- /Secure/ cabal repositories use a new extended & incremental
-- @01-index.tar@. In order to avoid issues resulting from clobbering
-- new/old-style index data, we save them locally to different names.
--
-- Example: Use @indexBaseName repo <.> "tar.gz"@ to compute the 'FilePath' of the
-- @00-index.tar.gz@/@01-index.tar.gz@ file.
indexBaseName :: Repo -> FilePath
indexBaseName repo = repoLocalDir repo </> fn
where
fn = case repo of
RepoSecure {} -> "01-index"
RepoRemote {} -> "00-index"
RepoLocal {} -> "00-index"
------------------------------------------------------------------------
-- Reading the source package index
--
......@@ -206,15 +223,14 @@ readRepoIndex verbosity repoCtxt repo =
-- | Return the age of the index file in days (as a Double).
getIndexFileAge :: Repo -> IO Double
getIndexFileAge repo = getFileAge $ repoLocalDir repo </> "00-index.tar"
getIndexFileAge repo = getFileAge $ indexBaseName repo <.> "tar"
-- | A set of files (or directories) that can be monitored to detect when
-- there might have been a change in the source packages.
--
getSourcePackagesMonitorFiles :: [Repo] -> [FilePath]
getSourcePackagesMonitorFiles repos =
[ repoLocalDir repo </> "00-index.cache"
| repo <- repos ]
[ indexBaseName repo <.> "cache" | repo <- repos ]
-- | It is not necessary to call this, as the cache will be updated when the
-- index is read normally. However you can do the work earlier if you like.
......@@ -386,11 +402,11 @@ data Index =
| SandboxIndex FilePath
indexFile :: Index -> FilePath
indexFile (RepoIndex _ctxt repo) = repoLocalDir repo </> "00-index.tar"
indexFile (RepoIndex _ctxt repo) = indexBaseName repo <.> "tar"
indexFile (SandboxIndex index) = index
cacheFile :: Index -> FilePath
cacheFile (RepoIndex _ctxt repo) = repoLocalDir repo </> "00-index.cache"
cacheFile (RepoIndex _ctxt repo) = indexBaseName repo <.> "cache"
cacheFile (SandboxIndex index) = index `replaceExtension` "cache"
updatePackageIndexCacheFile :: Verbosity -> Index -> IO ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment