diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-07-27 10:46:25 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-07-27 10:46:25 -0400 |
commit | d87485c2b532ad2d52aa1829a1b30e3519d2cbb1 (patch) | |
tree | 24ae6d6ef4a807c81534ba56c7fcb9e7c2a6ba28 /Types | |
parent | 2cb464a0e641254aa28a788587b089022922577a (diff) |
Added metadata --batch option, which allows getting, setting, deleting, and modifying metadata for multiple files/keys.
Diffstat (limited to 'Types')
-rw-r--r-- | Types/MetaData.hs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Types/MetaData.hs b/Types/MetaData.hs index a62dd7ed0..9e153ffb9 100644 --- a/Types/MetaData.hs +++ b/Types/MetaData.hs @@ -204,8 +204,11 @@ emptyMetaData = MetaData M.empty {- Can be used to set a value, or to unset it, depending on whether - the MetaValue has CurrentlySet or not. -} updateMetaData :: MetaField -> MetaValue -> MetaData -> MetaData -updateMetaData f v (MetaData m) = MetaData $ - M.insertWith' S.union f (S.singleton v) m +updateMetaData f v = updateMetaData' f (S.singleton v) + +updateMetaData' :: MetaField -> S.Set MetaValue -> MetaData -> MetaData +updateMetaData' f s (MetaData m) = MetaData $ + M.insertWith' S.union f s m {- New metadata overrides old._-} unionMetaData :: MetaData -> MetaData -> MetaData @@ -247,7 +250,7 @@ data ModMeta | DelMeta MetaField (Maybe MetaValue) -- ^ delete value of a field. With Just, only that specific value -- is deleted; with Nothing, all current values are deleted. - | SetMeta MetaField MetaValue + | SetMeta MetaField (S.Set MetaValue) -- ^ removes any existing values | MaybeSetMeta MetaField MetaValue -- ^ set when field has no existing value @@ -262,7 +265,7 @@ modMeta _ (DelMeta f (Just oldv)) = updateMetaData f (unsetMetaValue oldv) emptyMetaData modMeta m (DelMeta f Nothing) = MetaData $ M.singleton f $ S.fromList $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m -modMeta m (SetMeta f v) = updateMetaData f v $ +modMeta m (SetMeta f s) = updateMetaData' f s $ foldr (updateMetaData f) emptyMetaData $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m modMeta m (MaybeSetMeta f v) |