add annex.dbdir (WIP)
WIP: This is mostly complete, but there is a problem: createDirectoryUnder throws an error when annex.dbdir is set to outside the git repo. annex.dbdir is a workaround for filesystems where sqlite does not work, due to eg, the filesystem not properly supporting locking. It's intended to be set before initializing the repository. Changing it in an existing repository can be done, but would be the same as making a new repository and moving all the annexed objects into it. While the databases get recreated from the git-annex branch in that situation, any information that is in the databases but not stored in the branch gets lost. It may be that no information ever gets stored in the databases that cannot be reconstructed from the branch, but I have not verified that. Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
parent
425deaf615
commit
e60766543f
26 changed files with 152 additions and 104 deletions
11
Logs/File.hs
11
Logs/File.hs
|
@ -1,6 +1,6 @@
|
|||
{- git-annex log files
|
||||
-
|
||||
- Copyright 2018-2020 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2018-2022 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -20,7 +20,6 @@ import Annex.Common
|
|||
import Annex.Perms
|
||||
import Annex.LockFile
|
||||
import Annex.ReplaceFile
|
||||
import qualified Git
|
||||
import Utility.Tmp
|
||||
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
|
@ -51,7 +50,7 @@ withLogHandle f a = do
|
|||
|
||||
-- | Appends a line to a log file, first locking it to prevent
|
||||
-- concurrent writers.
|
||||
appendLogFile :: RawFilePath -> (Git.Repo -> RawFilePath) -> L.ByteString -> Annex ()
|
||||
appendLogFile :: RawFilePath -> RawFilePath -> L.ByteString -> Annex ()
|
||||
appendLogFile f lck c =
|
||||
createDirWhenNeeded f $
|
||||
withExclusiveLock lck $ do
|
||||
|
@ -69,7 +68,7 @@ appendLogFile f lck c =
|
|||
--
|
||||
-- The file is locked to prevent concurrent writers, and it is written
|
||||
-- atomically.
|
||||
modifyLogFile :: RawFilePath -> (Git.Repo -> RawFilePath) -> ([L.ByteString] -> [L.ByteString]) -> Annex ()
|
||||
modifyLogFile :: RawFilePath -> RawFilePath -> ([L.ByteString] -> [L.ByteString]) -> Annex ()
|
||||
modifyLogFile f lck modf = withExclusiveLock lck $ do
|
||||
ls <- liftIO $ fromMaybe []
|
||||
<$> tryWhenExists (L8.lines <$> L.readFile f')
|
||||
|
@ -89,7 +88,7 @@ modifyLogFile f lck modf = withExclusiveLock lck $ do
|
|||
-- action is concurrently modifying the file. It does not lock the file,
|
||||
-- for speed, but instead relies on the fact that a log file usually
|
||||
-- ends in a newline.
|
||||
checkLogFile :: FilePath -> (Git.Repo -> RawFilePath) -> (L.ByteString -> Bool) -> Annex Bool
|
||||
checkLogFile :: FilePath -> RawFilePath -> (L.ByteString -> Bool) -> Annex Bool
|
||||
checkLogFile f lck matchf = withExclusiveLock lck $ bracket setup cleanup go
|
||||
where
|
||||
setup = liftIO $ tryWhenExists $ openFile f ReadMode
|
||||
|
@ -123,7 +122,7 @@ fullLines = go []
|
|||
--
|
||||
-- Locking is used to prevent writes to to the log file while this
|
||||
-- is running.
|
||||
streamLogFile :: FilePath -> (Git.Repo -> RawFilePath) -> (String -> Annex ()) -> Annex ()
|
||||
streamLogFile :: FilePath -> RawFilePath -> (String -> Annex ()) -> Annex ()
|
||||
streamLogFile f lck a = withExclusiveLock lck $ bracketOnError setup cleanup go
|
||||
where
|
||||
setup = liftIO $ tryWhenExists $ openFile f ReadMode
|
||||
|
|
|
@ -19,7 +19,8 @@ import qualified Data.ByteString.Lazy as L
|
|||
smudgeLog :: Key -> TopFilePath -> Annex ()
|
||||
smudgeLog k f = do
|
||||
logf <- fromRepo gitAnnexSmudgeLog
|
||||
appendLogFile logf gitAnnexSmudgeLock $ L.fromStrict $
|
||||
lckf <- fromRepo gitAnnexSmudgeLock
|
||||
appendLogFile logf lckf $ L.fromStrict $
|
||||
serializeKey' k <> " " <> getTopFilePath f
|
||||
|
||||
-- | Streams all smudged files, and then empties the log at the end.
|
||||
|
@ -32,7 +33,8 @@ smudgeLog k f = do
|
|||
streamSmudged :: (Key -> TopFilePath -> Annex ()) -> Annex ()
|
||||
streamSmudged a = do
|
||||
logf <- fromRepo gitAnnexSmudgeLog
|
||||
streamLogFile (fromRawFilePath logf) gitAnnexSmudgeLock $ \l ->
|
||||
lckf <- fromRepo gitAnnexSmudgeLock
|
||||
streamLogFile (fromRawFilePath logf) lckf $ \l ->
|
||||
case parse l of
|
||||
Nothing -> noop
|
||||
Just (k, f) -> a k f
|
||||
|
|
|
@ -24,8 +24,9 @@ import Data.Time.Clock.POSIX
|
|||
|
||||
writeUpgradeLog :: RepoVersion -> POSIXTime-> Annex ()
|
||||
writeUpgradeLog v t = do
|
||||
logfile <- fromRepo gitAnnexUpgradeLog
|
||||
appendLogFile logfile gitAnnexUpgradeLock $ encodeBL $
|
||||
logf <- fromRepo gitAnnexUpgradeLog
|
||||
lckf <- fromRepo gitAnnexUpgradeLock
|
||||
appendLogFile logf lckf $ encodeBL $
|
||||
show (fromRepoVersion v) ++ " " ++ show t
|
||||
|
||||
readUpgradeLog :: Annex [(RepoVersion, POSIXTime)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue