summaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-28 15:28:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-28 15:28:20 -0400
commit653ad35a9f728ed5b3e9b557cdfb15a19b4afe16 (patch)
tree40e8ed2880ea291f33ef20e931b9d9d1d8c7189c /Backend
parent92e5d28ca83d057a3d8f5d7d30806642de699172 (diff)
In .gitattributes, the git-annex-numcopies attribute can be used to control the number of copies to retain of different types of files.
Diffstat (limited to 'Backend')
-rw-r--r--Backend/File.hs25
-rw-r--r--Backend/URL.hs10
2 files changed, 21 insertions, 14 deletions
diff --git a/Backend/File.hs b/Backend/File.hs
index c0fc46992..5984348b3 100644
--- a/Backend/File.hs
+++ b/Backend/File.hs
@@ -86,14 +86,14 @@ copyKeyFile key file = do
{- Checks remotes to verify that enough copies of a key exist to allow
- for a key to be safely removed (with no data loss), and fails with an
- error if not. -}
-checkRemoveKey :: Key -> Annex Bool
-checkRemoveKey key = do
+checkRemoveKey :: Key -> Maybe Int -> Annex Bool
+checkRemoveKey key numcopiesM = do
force <- Annex.flagIsSet "force"
- if force
+ if force || numcopiesM == Just 0
then return True
else do
remotes <- Remotes.keyPossibilities key
- numcopies <- getNumCopies
+ numcopies <- getNumCopies numcopiesM
if numcopies > length remotes
then notEnoughCopies numcopies (length remotes) []
else findcopies numcopies 0 remotes []
@@ -139,8 +139,9 @@ showTriedRemotes remotes =
showLongNote $ "I was unable to access these remotes: " ++
Remotes.list remotes
-getNumCopies :: Annex Int
-getNumCopies = do
+getNumCopies :: Maybe Int -> Annex Int
+getNumCopies (Just n) = return n
+getNumCopies Nothing = do
g <- Annex.gitRepo
return $ read $ Git.configGet g config "1"
where
@@ -153,15 +154,15 @@ getNumCopies = do
- The passed action is first run to allow backends deriving this one
- to do their own checks.
-}
-checkKey :: (Key -> Annex Bool) -> Key -> Annex Bool
-checkKey a key = do
+checkKey :: (Key -> Annex Bool) -> Key -> Maybe Int -> Annex Bool
+checkKey a key numcopies = do
a_ok <- a key
- copies_ok <- checkKeyNumCopies key
+ copies_ok <- checkKeyNumCopies key numcopies
return $ a_ok && copies_ok
-checkKeyNumCopies :: Key -> Annex Bool
-checkKeyNumCopies key = do
- needed <- getNumCopies
+checkKeyNumCopies :: Key -> Maybe Int -> Annex Bool
+checkKeyNumCopies key numcopies = do
+ needed <- getNumCopies numcopies
remotes <- Remotes.keyPossibilities key
inannex <- inAnnex key
let present = length remotes + if inannex then 1 else 0
diff --git a/Backend/URL.hs b/Backend/URL.hs
index b38ea71c9..3eb7376e0 100644
--- a/Backend/URL.hs
+++ b/Backend/URL.hs
@@ -22,11 +22,11 @@ backend = Backend {
retrieveKeyFile = downloadUrl,
-- allow keys to be removed; presumably they can always be
-- downloaded again
- removeKey = dummyOk,
+ removeKey = dummyRemove,
-- similarly, keys are always assumed to be out there on the web
hasKey = dummyOk,
-- and nothing needed to fsck
- fsckKey = dummyOk
+ fsckKey = dummyFsck
}
-- cannot generate url from filename
@@ -37,6 +37,12 @@ keyValue _ = return Nothing
dummyStore :: FilePath -> Key -> Annex Bool
dummyStore _ _ = return False
+dummyRemove :: Key -> Maybe a -> Annex Bool
+dummyRemove _ _ = return False
+
+dummyFsck :: Key -> Maybe a -> Annex Bool
+dummyFsck _ _ = return True
+
dummyOk :: Key -> Annex Bool
dummyOk _ = return True