import Annex.Wanted
import Annex.CatFile
import Annex.Action (quiesce)
+import Annex.MetaData
import Logs.Group
import Logs.Trust
import Logs.PreferredContent
import Logs.Difference
import Logs.UUID
import Logs.Location
+import Logs.MetaData
import Utility.Env
import qualified Annex
import qualified Remote
, simNumCopies :: NumCopies
, simMinCopies :: MinCopies
, simGroups :: M.Map UUID (S.Set Group)
+ , simMetaData :: M.Map Key MetaData
, simWanted :: M.Map UUID PreferredContentExpression
, simRequired :: M.Map UUID PreferredContentExpression
, simGroupWanted :: M.Map Group PreferredContentExpression
, simNumCopies = configuredNumCopies 1
, simMinCopies = configuredMinCopies 1
, simGroups = mempty
+ , simMetaData = mempty
, simWanted = mempty
, simRequired = mempty
, simGroupWanted = mempty
| CommandTrustLevel RepoName TrustLevel
| CommandGroup RepoName Group
| CommandUngroup RepoName Group
+ | CommandMetaData RawFilePath String
| CommandWanted RepoName PreferredContentExpression
| CommandRequired RepoName PreferredContentExpression
| CommandGroupWanted Group PreferredContentExpression
Right $ Right $ st
{ simGroups = M.adjust (S.delete groupname) u (simGroups st)
}
+applySimCommand' (CommandMetaData file modmetaexpr) st _ =
+ case parseModMeta modmetaexpr of
+ Left err -> Left err
+ Right modmeta -> case M.lookup file (simFiles st) of
+ Nothing -> Left $ "Cannot set metadata of unknown file " ++ fromRawFilePath file
+ Just k -> Right $ Right $ st
+ { simMetaData = M.alter (addmeta modmeta) k
+ (simMetaData st)
+ }
+ where
+ addmeta modmeta (Just metadata) = Just $ unionMetaData metadata $
+ modMeta metadata modmeta
+ addmeta modmeta Nothing = Just $ modMeta emptyMetaData modmeta
applySimCommand' (CommandWanted repo expr) st _ =
checkKnownRepo repo st $ \u ->
checkValidPreferredContentExpression [expr] $ Right $ st
, addDiff = \u -> groupChange u . const
, removeDiff = const . flip groupChange (const mempty)
}
+ updateField oldst newst simMetaData $ DiffUpdate
+ { replaceDiff = replaceNew addMetaData
+ , addDiff = addMetaData
+ , removeDiff = \k old -> addMetaData k $
+ modMeta old DelAllMeta
+ }
updateField oldst newst simWanted $ DiffUpdate
{ replaceDiff = replaceNew preferredContentSet
, addDiff = preferredContentSet
["group", repo, fromGroup group] : go rest
go (CommandUngroup (RepoName repo) group : rest) =
["ungroup", repo, fromGroup group] : go rest
+ go (CommandMetaData f modmeta : rest) =
+ ["metadata", fromRawFilePath f, modmeta] : go rest
go (CommandWanted (RepoName repo) expr : rest) =
["wanted", repo, expr] : go rest
go (CommandRequired (RepoName repo) expr : rest) =
Right $ CommandGroup (RepoName repo) (toGroup group)
parseSimCommand ("ungroup":repo:group:[]) =
Right $ CommandUngroup (RepoName repo) (toGroup group)
+parseSimCommand ("metadata":file:modmeta:[]) =
+ Right $ CommandMetaData (toRawFilePath file) modmeta
parseSimCommand ("wanted":repo:expr) =
Right $ CommandWanted (RepoName repo) (unwords expr)
parseSimCommand ("required":repo:expr) =
import qualified Data.ByteString.Char8 as B8
newtype MetaData = MetaData (M.Map MetaField (S.Set MetaValue))
- deriving (Show, Eq, Ord)
+ deriving (Read, Show, Eq, Ord)
instance ToJSON' MetaData where
toJSON' (MetaData m) = object $ map go (M.toList m)
Sets the trust level of the repository. This is equivilant to
[[git-annex-trust]](1), [[git-annex-untrust]](1), etc.
-* `group repo group`
-
- Add a repository to a group. This is equivilant to
- [[git-annex-group]](1).
-
-* `ungroup repo group`
-
- Remove a repository from a group. This is equivilant to
- [[git-annex-ungroup]](1).
-
* `wanted repo expression`
Configure the preferred content of a repository. This is equivilant
Configure the groupwanted to a random expression.
+* `group repo group`
+
+ Add a repository to a group. This is equivilant to
+ [[git-annex-group]](1).
+
+* `ungroup repo group`
+
+ Remove a repository from a group. This is equivilant to
+ [[git-annex-ungroup]](1).
+
+* `metadata filename expression`
+
+ Change the metadata of the simulated file. The expression is
+ in the same format as the --set option of the [[git-annex-metadata]]
+ command. For example: `metadata foo year=2025`
+
* `maxsize repo size`
Configure the maximum size of a repository. This is equivilant to
## work notes
-* Currently working in [[todo/proving_preferred_content_behavior]]
- in the `sim` branch.
-
-* sim: Add support for metadata, so preferred content that matches on it
- will work
+* Currently working in [[todo/proving_preferred_content_behavior]].
* The sim cannot be safely interrupted, or two processes be run
concurrently. Both unlike other git-annex commands. Either document these