add hasKey
This commit is contained in:
		
					parent
					
						
							
								4b7e54eddb
							
						
					
				
			
			
				commit
				
					
						859731ee5b
					
				
			
		
					 3 changed files with 17 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -13,13 +13,16 @@ import LocationLog
 | 
			
		|||
import Locations
 | 
			
		||||
import qualified Remotes
 | 
			
		||||
import qualified GitRepo as Git
 | 
			
		||||
import Utility
 | 
			
		||||
import Core
 | 
			
		||||
 | 
			
		||||
backend = Backend {
 | 
			
		||||
	name = "file",
 | 
			
		||||
	getKey = keyValue,
 | 
			
		||||
	storeFileKey = dummyStore,
 | 
			
		||||
	retrieveKeyFile = copyKeyFile,
 | 
			
		||||
	removeKey = dummyRemove
 | 
			
		||||
	removeKey = dummyRemove,
 | 
			
		||||
	hasKey = checkKeyFile
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- 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,
 | 
			
		||||
 - it relies on the file contents in .git/annex/ in this repo,
 | 
			
		||||
 - and other accessible repos. So storing a key is
 | 
			
		||||
 - a no-op. TODO until support is added for git annex --push otherrepo,
 | 
			
		||||
 - then these could implement that.. -}
 | 
			
		||||
 - a no-op. -}
 | 
			
		||||
dummyStore :: FilePath -> Key -> Annex (Bool)
 | 
			
		||||
dummyStore file key = return True
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +40,10 @@ dummyStore file key = return True
 | 
			
		|||
dummyRemove :: Key -> Annex Bool
 | 
			
		||||
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,
 | 
			
		||||
 - and copy it over to this one. -}
 | 
			
		||||
copyKeyFile :: Key -> FilePath -> Annex (Bool)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,8 @@ backend = Backend {
 | 
			
		|||
	getKey = keyValue,
 | 
			
		||||
	storeFileKey = dummyStore,
 | 
			
		||||
	retrieveKeyFile = downloadUrl,
 | 
			
		||||
	removeKey = dummyRemove
 | 
			
		||||
	removeKey = dummyOk,
 | 
			
		||||
	hasKey = dummyOk
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- cannot generate url from filename
 | 
			
		||||
| 
						 | 
				
			
			@ -24,9 +25,9 @@ keyValue file = return Nothing
 | 
			
		|||
dummyStore :: FilePath -> Key -> Annex Bool
 | 
			
		||||
dummyStore file url = return False
 | 
			
		||||
 | 
			
		||||
-- allow keys to be removed
 | 
			
		||||
dummyRemove :: Key -> Annex Bool
 | 
			
		||||
dummyRemove url = return True
 | 
			
		||||
-- allow keys to be removed; presumably they can always be downloaded again
 | 
			
		||||
dummyOk :: Key -> Annex Bool
 | 
			
		||||
dummyOk url = return True
 | 
			
		||||
 | 
			
		||||
downloadUrl :: Key -> FilePath -> Annex Bool
 | 
			
		||||
downloadUrl url file = do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,7 +37,9 @@ data Backend = Backend {
 | 
			
		|||
	-- retrieves a key's contents to a file
 | 
			
		||||
	retrieveKeyFile :: Key -> FilePath -> Annex Bool,
 | 
			
		||||
	-- 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue