summaryrefslogtreecommitdiff
path: root/Types/MetaData.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-09-28 12:36:10 -0400
committerJoey Hess <joeyh@joeyh.name>2017-09-28 12:36:10 -0400
commit812d90022b15b7704ee3a16f5b4eeed543ab0968 (patch)
treee5a4a91afa2bde5deb243917df0db7c1e1fa13aa /Types/MetaData.hs
parentb4d13c75a1ebf52d74b58993a7b950614d5cf42c (diff)
metadata: Added --remove-all.
Motivation is to remove all metadata when it gets copied from a previous version of the file, and that is not deisrable. This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Types/MetaData.hs')
-rw-r--r--Types/MetaData.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/Types/MetaData.hs b/Types/MetaData.hs
index 9e153ffb9a..bc27c345f4 100644
--- a/Types/MetaData.hs
+++ b/Types/MetaData.hs
@@ -244,12 +244,17 @@ removeEmptyFields (MetaData m) = MetaData $ M.filter (not . S.null) m
metaDataValues :: MetaField -> MetaData -> S.Set MetaValue
metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m)
+mapMetaData :: (S.Set MetaValue -> S.Set MetaValue) -> MetaData -> MetaData
+mapMetaData f (MetaData m) = MetaData (M.map f m)
+
{- Ways that existing metadata can be modified -}
data ModMeta
= AddMeta MetaField MetaValue
| DelMeta MetaField (Maybe MetaValue)
-- ^ delete value of a field. With Just, only that specific value
- -- is deleted; with Nothing, all current values are deleted.
+ -- is deleted; with Nothing, all current values are deleted.a
+ | DelAllMeta
+ -- ^ delete all currently set metadata
| SetMeta MetaField (S.Set MetaValue)
-- ^ removes any existing values
| MaybeSetMeta MetaField MetaValue
@@ -265,6 +270,9 @@ 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 DelAllMeta = mapMetaData
+ (S.fromList . map unsetMetaValue . S.toList)
+ (currentMetaData m)
modMeta m (SetMeta f s) = updateMetaData' f s $
foldr (updateMetaData f) emptyMetaData $
map unsetMetaValue $ S.toList $ currentMetaDataValues f m