summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-03 13:46:09 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-03 14:15:00 -0400
commit38e2750137330da8fcc7067a2fa2e5aa74be5125 (patch)
tree22b7d238cbe66ab5ed3444b91f448b7de5097dc5 /Annex
parentff0cf010c169e7d4868994a7eca428496f9e54e6 (diff)
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files that are imported from it. Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names that are used in --template. Also added title and author, which are the item title/author if available, falling back to the feed title/author. These are more likely to be common metadata fields. (There is a small bit of dupication here, but once git gets around to packing the object, it will compress it away.) The itempubdate field is not included in the metadata as a string; instead it is used to generate year and month fields, same as is done when adding files with annex.genmetadata set. This commit was sponsored by Amitai Schlair, who cooincidentially is responsible for ikiwiki generating nice feed metadata!
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Content.hs8
-rw-r--r--Annex/MetaData.hs19
2 files changed, 13 insertions, 14 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index aaae595aa..8ad3d5e65 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -218,7 +218,7 @@ getViaTmpUnchecked = finishGetViaTmp (return True)
getViaTmpChecked :: Annex Bool -> Key -> (FilePath -> Annex Bool) -> Annex Bool
getViaTmpChecked check key action =
- prepGetViaTmpChecked key $
+ prepGetViaTmpChecked key False $
finishGetViaTmp check key action
{- Prepares to download a key via a tmp file, and checks that there is
@@ -229,8 +229,8 @@ getViaTmpChecked check key action =
-
- Wen there's enough free space, runs the download action.
-}
-prepGetViaTmpChecked :: Key -> Annex Bool -> Annex Bool
-prepGetViaTmpChecked key getkey = do
+prepGetViaTmpChecked :: Key -> a -> Annex a -> Annex a
+prepGetViaTmpChecked key unabletoget getkey = do
tmp <- fromRepo $ gitAnnexTmpObjectLocation key
e <- liftIO $ doesFileExist tmp
@@ -242,7 +242,7 @@ prepGetViaTmpChecked key getkey = do
-- The tmp file may not have been left writable
when e $ thawContent tmp
getkey
- , return False
+ , return unabletoget
)
finishGetViaTmp :: Annex Bool -> Key -> (FilePath -> Annex Bool) -> Annex Bool
diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs
index f382f0ab1..f1b79e3f4 100644
--- a/Annex/MetaData.hs
+++ b/Annex/MetaData.hs
@@ -7,6 +7,7 @@
module Annex.MetaData (
genMetaData,
+ addDateMetaData,
module X
) where
@@ -37,20 +38,18 @@ genMetaData :: Key -> FilePath -> FileStatus -> Annex ()
genMetaData key file status = do
maybe noop (flip copyMetaData key) =<< catKeyFileHEAD file
whenM (annexGenMetaData <$> Annex.getGitConfig) $ do
- metadata <- getCurrentMetaData key
- let metadata' = genMetaData' status metadata
- unless (metadata' == emptyMetaData) $
- addMetaData key metadata'
+ curr <- getCurrentMetaData key
+ addMetaData key (addDateMetaData mtime curr)
+ where
+ mtime = posixSecondsToUTCTime $ realToFrac $ modificationTime status
-{- Generates metadata from the FileStatus.
+{- Generates metadata for a file's date stamp.
- Does not overwrite any existing metadata values. -}
-genMetaData' :: FileStatus -> MetaData -> MetaData
-genMetaData' status old = MetaData $ M.fromList $ filter isnew
+addDateMetaData :: UTCTime -> MetaData -> MetaData
+addDateMetaData mtime old = MetaData $ M.fromList $ filter isnew
[ (yearMetaField, S.singleton $ toMetaValue $ show y)
, (monthMetaField, S.singleton $ toMetaValue $ show m)
]
where
isnew (f, _) = S.null (currentMetaDataValues f old)
- (y, m, _d) = toGregorian $ utctDay $
- posixSecondsToUTCTime $ realToFrac $
- modificationTime status
+ (y, m, _d) = toGregorian $ utctDay $ mtime