2014-01-20 20:47:56 +00:00
|
|
|
{- git-annex numcopies log
|
|
|
|
-
|
2021-01-06 18:11:08 +00:00
|
|
|
- Copyright 2014-2021 Joey Hess <id@joeyh.name>
|
2014-01-20 20:47:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-01-20 20:47:56 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
module Logs.NumCopies (
|
|
|
|
setGlobalNumCopies,
|
2021-01-06 18:11:08 +00:00
|
|
|
setGlobalMinCopies,
|
2014-01-21 20:08:19 +00:00
|
|
|
getGlobalNumCopies,
|
2021-01-06 18:11:08 +00:00
|
|
|
getGlobalMinCopies,
|
2014-01-21 20:08:19 +00:00
|
|
|
globalNumCopiesLoad,
|
2021-01-06 18:11:08 +00:00
|
|
|
globalMinCopiesLoad,
|
2014-01-21 20:08:19 +00:00
|
|
|
) where
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-01-20 20:47:56 +00:00
|
|
|
import qualified Annex
|
start implementing hidden git-annex repositories
This adds a separate journal, which does not currently get committed to
an index, but is planned to be committed to .git/annex/index-private.
Changes that are regarding a UUID that is private will get written to
this journal, and so will not be published into the git-annex branch.
All log writing should have been made to indicate the UUID it's
regarding, though I've not verified this yet.
Currently, no UUIDs are treated as private yet, a way to configure that
is needed.
The implementation is careful to not add any additional IO work when
privateUUIDsKnown is False. It will skip looking at the private journal
at all. So this should be free, or nearly so, unless the feature is
used. When it is used, all branch reads will be about twice as expensive.
It is very lucky -- or very prudent design -- that Annex.Branch.change
and maybeChange are the only ways to change a file on the branch,
and Annex.Branch.set is only internal use. That let Annex.Branch.get
always yield any private information that has been recorded, without
the risk that Annex.Branch.set might be called, with a non-private UUID,
and end up leaking the private information into the git-annex branch.
And, this relies on the way git-annex union merges the git-annex branch.
When reading a file, there can be a public and a private version, and
they are just concacenated together. That will be handled the same as if
there were two diverged git-annex branches that got union merged.
2021-04-20 18:32:41 +00:00
|
|
|
import qualified Annex.Branch
|
2014-01-21 20:08:19 +00:00
|
|
|
import Types.NumCopies
|
2014-01-20 20:47:56 +00:00
|
|
|
import Logs
|
|
|
|
import Logs.SingleValue
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
instance SingleValueSerializable NumCopies where
|
2022-03-28 19:19:52 +00:00
|
|
|
serialize = encodeBS . show . fromNumCopies
|
|
|
|
deserialize = configuredNumCopies <$$> readish . decodeBS
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
instance SingleValueSerializable MinCopies where
|
2022-03-28 19:19:52 +00:00
|
|
|
serialize = encodeBS . show . fromMinCopies
|
|
|
|
deserialize = configuredMinCopies <$$> readish . decodeBS
|
2021-01-06 18:11:08 +00:00
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
setGlobalNumCopies :: NumCopies -> Annex ()
|
2017-01-30 19:11:26 +00:00
|
|
|
setGlobalNumCopies new = do
|
|
|
|
curr <- getGlobalNumCopies
|
|
|
|
when (curr /= Just new) $
|
start implementing hidden git-annex repositories
This adds a separate journal, which does not currently get committed to
an index, but is planned to be committed to .git/annex/index-private.
Changes that are regarding a UUID that is private will get written to
this journal, and so will not be published into the git-annex branch.
All log writing should have been made to indicate the UUID it's
regarding, though I've not verified this yet.
Currently, no UUIDs are treated as private yet, a way to configure that
is needed.
The implementation is careful to not add any additional IO work when
privateUUIDsKnown is False. It will skip looking at the private journal
at all. So this should be free, or nearly so, unless the feature is
used. When it is used, all branch reads will be about twice as expensive.
It is very lucky -- or very prudent design -- that Annex.Branch.change
and maybeChange are the only ways to change a file on the branch,
and Annex.Branch.set is only internal use. That let Annex.Branch.get
always yield any private information that has been recorded, without
the risk that Annex.Branch.set might be called, with a non-private UUID,
and end up leaking the private information into the git-annex branch.
And, this relies on the way git-annex union merges the git-annex branch.
When reading a file, there can be a public and a private version, and
they are just concacenated together. That will be handled the same as if
there were two diverged git-annex branches that got union merged.
2021-04-20 18:32:41 +00:00
|
|
|
setLog (Annex.Branch.RegardingUUID []) numcopiesLog new
|
2024-09-20 20:52:17 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.globalnumcopies = Nothing }
|
2014-01-20 20:47:56 +00:00
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
setGlobalMinCopies :: MinCopies -> Annex ()
|
|
|
|
setGlobalMinCopies new = do
|
|
|
|
curr <- getGlobalMinCopies
|
|
|
|
when (curr /= Just new) $
|
start implementing hidden git-annex repositories
This adds a separate journal, which does not currently get committed to
an index, but is planned to be committed to .git/annex/index-private.
Changes that are regarding a UUID that is private will get written to
this journal, and so will not be published into the git-annex branch.
All log writing should have been made to indicate the UUID it's
regarding, though I've not verified this yet.
Currently, no UUIDs are treated as private yet, a way to configure that
is needed.
The implementation is careful to not add any additional IO work when
privateUUIDsKnown is False. It will skip looking at the private journal
at all. So this should be free, or nearly so, unless the feature is
used. When it is used, all branch reads will be about twice as expensive.
It is very lucky -- or very prudent design -- that Annex.Branch.change
and maybeChange are the only ways to change a file on the branch,
and Annex.Branch.set is only internal use. That let Annex.Branch.get
always yield any private information that has been recorded, without
the risk that Annex.Branch.set might be called, with a non-private UUID,
and end up leaking the private information into the git-annex branch.
And, this relies on the way git-annex union merges the git-annex branch.
When reading a file, there can be a public and a private version, and
they are just concacenated together. That will be handled the same as if
there were two diverged git-annex branches that got union merged.
2021-04-20 18:32:41 +00:00
|
|
|
setLog (Annex.Branch.RegardingUUID []) mincopiesLog new
|
2024-09-20 20:52:17 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.globalmincopies = Nothing }
|
2021-01-06 18:11:08 +00:00
|
|
|
|
2014-01-21 21:08:49 +00:00
|
|
|
{- Value configured in the numcopies log. Cached for speed. -}
|
2014-01-21 20:08:19 +00:00
|
|
|
getGlobalNumCopies :: Annex (Maybe NumCopies)
|
2023-06-06 18:15:47 +00:00
|
|
|
getGlobalNumCopies = maybe globalNumCopiesLoad return
|
2014-01-20 20:47:56 +00:00
|
|
|
=<< Annex.getState Annex.globalnumcopies
|
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
{- Value configured in the mincopies log. Cached for speed. -}
|
|
|
|
getGlobalMinCopies :: Annex (Maybe MinCopies)
|
2023-06-06 18:15:47 +00:00
|
|
|
getGlobalMinCopies = maybe globalMinCopiesLoad return
|
2021-01-06 18:11:08 +00:00
|
|
|
=<< Annex.getState Annex.globalmincopies
|
|
|
|
|
2014-01-21 20:08:19 +00:00
|
|
|
globalNumCopiesLoad :: Annex (Maybe NumCopies)
|
|
|
|
globalNumCopiesLoad = do
|
2014-01-20 20:47:56 +00:00
|
|
|
v <- getLog numcopiesLog
|
2023-06-06 18:15:47 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.globalnumcopies = Just v }
|
2014-01-20 20:47:56 +00:00
|
|
|
return v
|
2021-01-06 18:11:08 +00:00
|
|
|
|
|
|
|
globalMinCopiesLoad :: Annex (Maybe MinCopies)
|
|
|
|
globalMinCopiesLoad = do
|
|
|
|
v <- getLog mincopiesLog
|
2023-06-06 18:15:47 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.globalmincopies = Just v }
|
2021-01-06 18:11:08 +00:00
|
|
|
return v
|