summaryrefslogtreecommitdiff
path: root/Backend/File.hs
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/File.hs
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/File.hs')
-rw-r--r--Backend/File.hs25
1 files changed, 13 insertions, 12 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