2018-10-25 18:43:13 +00:00
|
|
|
{- git-annex smudge log file
|
|
|
|
-
|
|
|
|
- Copyright 2018 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2019-12-09 17:49:05 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2018-10-25 18:43:13 +00:00
|
|
|
module Logs.Smudge where
|
|
|
|
|
|
|
|
import Annex.Common
|
|
|
|
import Git.FilePath
|
|
|
|
import Logs.File
|
|
|
|
|
2020-10-20 20:42:28 +00:00
|
|
|
import qualified Data.ByteString.Lazy as L
|
|
|
|
|
2018-10-25 18:43:13 +00:00
|
|
|
-- | Log a smudged file.
|
|
|
|
smudgeLog :: Key -> TopFilePath -> Annex ()
|
|
|
|
smudgeLog k f = do
|
|
|
|
logf <- fromRepo gitAnnexSmudgeLog
|
2022-08-11 20:57:44 +00:00
|
|
|
lckf <- fromRepo gitAnnexSmudgeLock
|
|
|
|
appendLogFile logf lckf $ L.fromStrict $
|
2019-12-09 17:49:05 +00:00
|
|
|
serializeKey' k <> " " <> getTopFilePath f
|
2018-10-25 18:43:13 +00:00
|
|
|
|
|
|
|
-- | Streams all smudged files, and then empties the log at the end.
|
|
|
|
--
|
|
|
|
-- If the action is interrupted or throws an exception, the log file is
|
|
|
|
-- left unchanged.
|
|
|
|
--
|
|
|
|
-- Locking is used to prevent new items being added to the log while this
|
|
|
|
-- is running.
|
|
|
|
streamSmudged :: (Key -> TopFilePath -> Annex ()) -> Annex ()
|
|
|
|
streamSmudged a = do
|
|
|
|
logf <- fromRepo gitAnnexSmudgeLog
|
2022-08-11 20:57:44 +00:00
|
|
|
lckf <- fromRepo gitAnnexSmudgeLock
|
2022-09-23 17:49:01 +00:00
|
|
|
streamLogFile (fromRawFilePath logf) lckf noop $ \l ->
|
2018-10-25 18:43:13 +00:00
|
|
|
case parse l of
|
|
|
|
Nothing -> noop
|
|
|
|
Just (k, f) -> a k f
|
|
|
|
where
|
|
|
|
parse l =
|
|
|
|
let (ks, f) = separate (== ' ') l
|
|
|
|
in do
|
2019-01-14 17:03:35 +00:00
|
|
|
k <- deserializeKey ks
|
2019-12-09 17:49:05 +00:00
|
|
|
return (k, asTopFilePath (toRawFilePath f))
|