diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-05 19:51:03 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-05 19:51:03 -0400 |
commit | d3cee987caf20b309334b37bd1b89e8b9115cf0a (patch) | |
tree | 8c1a244545efed3b2fd9e48ea28faac12aa326fe /Backend | |
parent | 77188ff04d8d4d42b25daac9eeffbf10d8b663ac (diff) |
separate source of content from the filename associated with the key when generating a key
This already made migrate's code a lot simpler.
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/SHA.hs | 13 | ||||
-rw-r--r-- | Backend/URL.hs | 10 | ||||
-rw-r--r-- | Backend/WORM.hs | 18 |
3 files changed, 21 insertions, 20 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs index c2a6cf976..df613bbcd 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -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 diff --git a/Backend/URL.hs b/Backend/URL.hs index b98974cb4..cc9112a36 100644 --- a/Backend/URL.hs +++ b/Backend/URL.hs @@ -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 diff --git a/Backend/WORM.hs b/Backend/WORM.hs index c022fd413..630000fa2 100644 --- a/Backend/WORM.hs +++ b/Backend/WORM.hs @@ -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 |