git-annex/Logs/Chunk.hs
Joey Hess 40ecf58d4b
update licenses from GPL to AGPL
This does not change the overall license of the git-annex program, which
was already AGPL due to a number of sources files being AGPL already.

Legally speaking, I'm adding a new license under which these files are
now available; I already released their current contents under the GPL
license. Now they're dual licensed GPL and AGPL. However, I intend
for all my future changes to these files to only be released under the
AGPL license, and I won't be tracking the dual licensing status, so I'm
simply changing the license statement to say it's AGPL.

(In some cases, others wrote parts of the code of a file and released it
under the GPL; but in all cases I have contributed a significant portion
of the code in each file and it's that code that is getting the AGPL
license; the GPL license of other contributors allows combining with
AGPL code.)
2019-03-13 15:48:14 -04:00

54 lines
1.5 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. Intead, 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 <- liftIO currentVectorClock
config <- Annex.getGitConfig
Annex.Branch.change (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)