38b9ebc5fd
Noticed that Semigroup instance of Map is not suitable to use for MapLog. For example, it behaved like this: ghci> parseTrustLog "foo 1 timestamp=10\nfoo 2 timestamp=11" <> parseTrustLog "foo X timestamp=12" fromList [(UUID "foo",LogEntry {changed = VectorClock 11s, value = SemiTrusted})] Which was wrong, it lost the newer DeadTrusted value. Luckily, nothing used that Semigroup when operating on a MapLog. And this provides a safe instance. Sponsored-by: Graham Spencer on Patreon
57 lines
1.6 KiB
Haskell
57 lines
1.6 KiB
Haskell
{- Chunk logs.
|
|
-
|
|
- An object can be stored in chunked for on a remote; these logs keep
|
|
- track of the chunk size used, and the number of chunks.
|
|
-
|
|
- It's possible for a single object to be stored multiple times on the
|
|
- same remote using different chunk sizes. So, while this is a MapLog, it
|
|
- is not a normal UUIDBased log. Instead, it's a map from UUID and chunk
|
|
- size to number of chunks.
|
|
-
|
|
- Format: "timestamp uuid:chunksize chunkcount"
|
|
-
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Logs.Chunk (
|
|
ChunkMethod(..),
|
|
ChunkSize,
|
|
ChunkCount,
|
|
chunksStored,
|
|
chunksRemoved,
|
|
getCurrentChunks,
|
|
) where
|
|
|
|
import Annex.Common
|
|
import Logs
|
|
import Logs.MapLog
|
|
import qualified Annex.Branch
|
|
import Logs.Chunk.Pure
|
|
import qualified Annex
|
|
|
|
import qualified Data.Map as M
|
|
|
|
chunksStored :: UUID -> Key -> ChunkMethod -> ChunkCount -> Annex ()
|
|
chunksStored u k chunkmethod chunkcount = do
|
|
c <- currentVectorClock
|
|
config <- Annex.getGitConfig
|
|
Annex.Branch.change
|
|
(Annex.Branch.RegardingUUID [u])
|
|
(chunkLogFile config k)
|
|
(buildLog . changeMapLog c (u, chunkmethod) chunkcount . parseLog)
|
|
|
|
chunksRemoved :: UUID -> Key -> ChunkMethod -> Annex ()
|
|
chunksRemoved u k chunkmethod = chunksStored u k chunkmethod 0
|
|
|
|
getCurrentChunks :: UUID -> Key -> Annex [(ChunkMethod, ChunkCount)]
|
|
getCurrentChunks u k = do
|
|
config <- Annex.getGitConfig
|
|
select . parseLog <$> Annex.Branch.get (chunkLogFile config k)
|
|
where
|
|
select = filter (\(_m, ct) -> ct > 0)
|
|
. map (\((_ku, m), l) -> (m, value l))
|
|
. M.toList
|
|
. M.filterWithKey (\(ku, _m) _ -> ku == u)
|
|
. fromMapLog
|