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

View file

@ -20,11 +20,11 @@ backends :: [Backend]
backends = [backend]
backend :: Backend
backend = Backend {
name = "URL",
getKey = const (return Nothing),
fsckKey = Nothing
}
backend = Backend
{ name = "URL"
, getKey = const $ return Nothing
, fsckKey = Nothing
}
fromUrl :: String -> Maybe Integer -> Key
fromUrl url size = stubKey

View file

@ -15,11 +15,11 @@ backends :: [Backend]
backends = [backend]
backend :: Backend
backend = Backend {
name = "WORM",
getKey = keyValue,
fsckKey = Nothing
}
backend = Backend
{ name = "WORM"
, getKey = keyValue
, fsckKey = Nothing
}
{- The key includes the file size, modification time, and the
- basename of the filename.
@ -28,11 +28,11 @@ backend = Backend {
- while also allowing a file to be moved around while retaining the
- same key.
-}
keyValue :: FilePath -> Annex (Maybe Key)
keyValue file = do
stat <- liftIO $ getFileStatus file
keyValue :: KeySource -> Annex (Maybe Key)
keyValue source = do
stat <- liftIO $ getFileStatus $ contentLocation source
return $ Just Key {
keyName = takeFileName file,
keyName = takeFileName $ keyFilename source,
keyBackendName = name backend,
keySize = Just $ fromIntegral $ fileSize stat,
keyMtime = Just $ modificationTime stat