git-annex/Logs/Upgrade.hs
Joey Hess 9d5db6a09a
add upgrade.log
The upgrade from V9 uses this to avoid an automatic upgrade until 1 year
after the V9 update. It can also be used in future such situations.

Sponsored-by: Dartmouth College's Datalad project
2022-01-19 15:52:29 -04:00

52 lines
1.3 KiB
Haskell

{- git-annex upgrade log
-
- This file is stored locally in .git/annex/, not in the git-annex branch.
-
- The format: "version timestamp"
-
- Copyright 2022 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Logs.Upgrade (
writeUpgradeLog,
readUpgradeLog,
timeOfUpgrade,
) where
import Annex.Common
import Utility.TimeStamp
import Logs.File
import Types.RepoVersion
import Data.Time.Clock.POSIX
writeUpgradeLog :: RepoVersion -> POSIXTime-> Annex ()
writeUpgradeLog v t = do
logfile <- fromRepo gitAnnexUpgradeLog
appendLogFile logfile gitAnnexUpgradeLock $ encodeBL $
show (fromRepoVersion v) ++ " " ++ show t
readUpgradeLog :: Annex [(RepoVersion, POSIXTime)]
readUpgradeLog = do
logfile <- fromRawFilePath <$> fromRepo gitAnnexUpgradeLog
ifM (liftIO $ doesFileExist logfile)
( mapMaybe parse . lines
<$> liftIO (readFileStrict logfile)
, return []
)
where
parse line = case (readish sint, parsePOSIXTime ts) of
(Just v, Just t) -> Just (RepoVersion v, t)
_ -> Nothing
where
(sint, ts) = separate (== ' ') line
timeOfUpgrade :: RepoVersion -> Annex (Maybe POSIXTime)
timeOfUpgrade want = do
l <- readUpgradeLog
return $ case filter (\(v, _) -> v == want) l of
[] -> Nothing
l' -> Just (minimum (map snd l'))