add hasKey

This commit is contained in:
Joey Hess 2010-10-14 15:31:44 -04:00
parent 4b7e54eddb
commit 859731ee5b
3 changed files with 17 additions and 8 deletions

View file

@ -13,13 +13,16 @@ import LocationLog
import Locations import Locations
import qualified Remotes import qualified Remotes
import qualified GitRepo as Git import qualified GitRepo as Git
import Utility
import Core
backend = Backend { backend = Backend {
name = "file", name = "file",
getKey = keyValue, getKey = keyValue,
storeFileKey = dummyStore, storeFileKey = dummyStore,
retrieveKeyFile = copyKeyFile, retrieveKeyFile = copyKeyFile,
removeKey = dummyRemove removeKey = dummyRemove,
hasKey = checkKeyFile
} }
-- direct mapping from filename to key -- direct mapping from filename to key
@ -29,8 +32,7 @@ keyValue file = return $ Just $ Key file
{- This backend does not really do any independant data storage, {- This backend does not really do any independant data storage,
- it relies on the file contents in .git/annex/ in this repo, - it relies on the file contents in .git/annex/ in this repo,
- and other accessible repos. So storing a key is - and other accessible repos. So storing a key is
- a no-op. TODO until support is added for git annex --push otherrepo, - a no-op. -}
- then these could implement that.. -}
dummyStore :: FilePath -> Key -> Annex (Bool) dummyStore :: FilePath -> Key -> Annex (Bool)
dummyStore file key = return True dummyStore file key = return True
@ -38,6 +40,10 @@ dummyStore file key = return True
dummyRemove :: Key -> Annex Bool dummyRemove :: Key -> Annex Bool
dummyRemove url = return True dummyRemove url = return True
{- Just check if the .git/annex/ file for the key exists. -}
checkKeyFile :: Key -> Annex Bool
checkKeyFile k = inAnnex backend k
{- Try to find a copy of the file in one of the remotes, {- Try to find a copy of the file in one of the remotes,
- and copy it over to this one. -} - and copy it over to this one. -}
copyKeyFile :: Key -> FilePath -> Annex (Bool) copyKeyFile :: Key -> FilePath -> Annex (Bool)

View file

@ -13,7 +13,8 @@ backend = Backend {
getKey = keyValue, getKey = keyValue,
storeFileKey = dummyStore, storeFileKey = dummyStore,
retrieveKeyFile = downloadUrl, retrieveKeyFile = downloadUrl,
removeKey = dummyRemove removeKey = dummyOk,
hasKey = dummyOk
} }
-- cannot generate url from filename -- cannot generate url from filename
@ -24,9 +25,9 @@ keyValue file = return Nothing
dummyStore :: FilePath -> Key -> Annex Bool dummyStore :: FilePath -> Key -> Annex Bool
dummyStore file url = return False dummyStore file url = return False
-- allow keys to be removed -- allow keys to be removed; presumably they can always be downloaded again
dummyRemove :: Key -> Annex Bool dummyOk :: Key -> Annex Bool
dummyRemove url = return True dummyOk url = return True
downloadUrl :: Key -> FilePath -> Annex Bool downloadUrl :: Key -> FilePath -> Annex Bool
downloadUrl url file = do downloadUrl url file = do

View file

@ -37,7 +37,9 @@ data Backend = Backend {
-- retrieves a key's contents to a file -- retrieves a key's contents to a file
retrieveKeyFile :: Key -> FilePath -> Annex Bool, retrieveKeyFile :: Key -> FilePath -> Annex Bool,
-- removes a key -- removes a key
removeKey :: Key -> Annex Bool removeKey :: Key -> Annex Bool,
-- checks if a backend is storing the content of a key
hasKey :: Key -> Annex Bool
} }
instance Show Backend where instance Show Backend where