separate source of content from the filename associated with the key when generating a key

This already made migrate's code a lot simpler.
This commit is contained in:
Joey Hess 2012-06-05 19:51:03 -04:00
parent 77188ff04d
commit d3cee987ca
9 changed files with 59 additions and 57 deletions

View file

@ -69,9 +69,10 @@ shaN size file = do
command = fromJust $ shaCommand size
{- A key is a checksum of its contents. -}
keyValue :: SHASize -> FilePath -> Annex (Maybe Key)
keyValue size file = do
s <- shaN size file
keyValue :: SHASize -> KeySource -> Annex (Maybe Key)
keyValue size source = do
let file = contentLocation source
s <- shaN size file
stat <- liftIO $ getFileStatus file
return $ Just $ stubKey
{ keyName = s
@ -80,14 +81,14 @@ keyValue size file = do
}
{- Extension preserving keys. -}
keyValueE :: SHASize -> FilePath -> Annex (Maybe Key)
keyValueE size file = keyValue size file >>= maybe (return Nothing) addE
keyValueE :: SHASize -> KeySource -> Annex (Maybe Key)
keyValueE size source = keyValue size source >>= maybe (return Nothing) addE
where
addE k = return $ Just $ k
{ keyName = keyName k ++ extension
, keyBackendName = shaNameE size
}
naiveextension = takeExtension file
naiveextension = takeExtension $ keyFilename source
extension
-- long or newline containing extensions are
-- probably not really an extension