prevent numcopies or mincopies being configured to 0
Ignore annex.numcopies set to 0 in gitattributes or git config, or by git-annex numcopies or by --numcopies, since that configuration would make git-annex easily lose data. Same for mincopies. This is a continuation of the work to make data only be able to be lost when --force is used. It earlier led to the --trust option being disabled, and similar reasoning applies here. Most numcopies configs had docs that strongly discouraged setting it to 0 anyway. And I can't imagine a use case for setting to 0. Not that there might not be one, but it's just so far from the intended use case of git-annex, of managing and storing your data, that it does not seem like it makes sense to cater to such a hypothetical use case, where any git-annex drop can lose your data at any time. Using a smart constructor makes sure every place avoids 0. Note that this does mean that NumCopies is for the configured desired values, and not the actual existing number of copies, which of course can be 0. The name configuredNumCopies is used to make that clear. Sponsored-by: Brock Spratlen on Patreon
This commit is contained in:
parent
fdcb14d475
commit
d266a41f8d
16 changed files with 59 additions and 47 deletions
|
@ -252,7 +252,7 @@ checkDropAuto automode mremote afile key a =
|
|||
uuid <- getUUID
|
||||
let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote
|
||||
locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs
|
||||
if NumCopies (length locs') >= numcopies
|
||||
if length locs' >= fromNumCopies numcopies
|
||||
then a numcopies mincopies
|
||||
else stop
|
||||
| otherwise = a numcopies mincopies
|
||||
|
|
|
@ -517,8 +517,8 @@ checkKeyNumCopies key afile numcopies = do
|
|||
locs <- loggedLocations key
|
||||
(untrustedlocations, otherlocations) <- trustPartition UnTrusted locs
|
||||
(deadlocations, safelocations) <- trustPartition DeadTrusted otherlocations
|
||||
let present = NumCopies (length safelocations)
|
||||
if present < numcopies
|
||||
let present = length safelocations
|
||||
if present < fromNumCopies numcopies
|
||||
then ifM (pure (not hasafile) <&&> checkDead key)
|
||||
( do
|
||||
showLongNote $ "This key is dead, skipping."
|
||||
|
@ -527,21 +527,21 @@ checkKeyNumCopies key afile numcopies = do
|
|||
untrusted <- Remote.prettyPrintUUIDs "untrusted" untrustedlocations
|
||||
dead <- Remote.prettyPrintUUIDs "dead" deadlocations
|
||||
warning $ missingNote desc present numcopies untrusted dead
|
||||
when (fromNumCopies present == 0 && not hasafile) $
|
||||
when (present == 0 && not hasafile) $
|
||||
showLongNote "(Avoid this check by running: git annex dead --key )"
|
||||
return False
|
||||
)
|
||||
else return True
|
||||
|
||||
missingNote :: String -> NumCopies -> NumCopies -> String -> String -> String
|
||||
missingNote file (NumCopies 0) _ [] dead =
|
||||
missingNote :: String -> Int -> NumCopies -> String -> String -> String
|
||||
missingNote file 0 _ [] dead =
|
||||
"** No known copies exist of " ++ file ++ honorDead dead
|
||||
missingNote file (NumCopies 0) _ untrusted dead =
|
||||
missingNote file 0 _ untrusted dead =
|
||||
"Only these untrusted locations may have copies of " ++ file ++
|
||||
"\n" ++ untrusted ++
|
||||
"Back it up to trusted locations with git-annex copy." ++ honorDead dead
|
||||
missingNote file present needed [] _ =
|
||||
"Only " ++ show (fromNumCopies present) ++ " of " ++ show (fromNumCopies needed) ++
|
||||
"Only " ++ show present ++ " of " ++ show (fromNumCopies needed) ++
|
||||
" trustworthy copies exist of " ++ file ++
|
||||
"\nBack it up with git-annex copy."
|
||||
missingNote file present needed untrusted dead =
|
||||
|
|
|
@ -32,7 +32,7 @@ startGet = startingCustomOutput (ActionItemOther Nothing) $ next $ do
|
|||
|
||||
startSet :: Int -> CommandStart
|
||||
startSet n = startingUsualMessages "mincopies" ai si $ do
|
||||
setGlobalMinCopies $ MinCopies n
|
||||
setGlobalMinCopies $ configuredMinCopies n
|
||||
next $ return True
|
||||
where
|
||||
ai = ActionItemOther (Just $ show n)
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
module Command.NumCopies where
|
||||
|
||||
import Command
|
||||
import qualified Annex
|
||||
import Annex.NumCopies
|
||||
|
||||
cmd :: Command
|
||||
|
@ -28,11 +27,8 @@ start' setting _ startset [s] = case readish s of
|
|||
Nothing -> giveup $ "Bad number: " ++ s
|
||||
Just n
|
||||
| n > 0 -> startset n
|
||||
| n == 0 -> ifM (Annex.getState Annex.force)
|
||||
( startset n
|
||||
, giveup $ "Setting " ++ setting ++ " to 0 is very unsafe. You will lose data! If you really want to do that, specify --force."
|
||||
)
|
||||
| otherwise -> giveup "Number cannot be negative!"
|
||||
| n == 0 -> giveup $ "Cannot set " ++ setting ++ " to 0."
|
||||
| otherwise -> giveup $ setting ++ " cannot be negative!"
|
||||
start' _ _ _ _ = giveup "Specify a single number."
|
||||
|
||||
startGet :: CommandStart
|
||||
|
@ -50,7 +46,7 @@ startGet = startingCustomOutput (ActionItemOther Nothing) $ next $ do
|
|||
|
||||
startSet :: Int -> CommandStart
|
||||
startSet n = startingUsualMessages "numcopies" ai si $ do
|
||||
setGlobalNumCopies $ NumCopies n
|
||||
setGlobalNumCopies $ configuredNumCopies n
|
||||
next $ return True
|
||||
where
|
||||
ai = ActionItemOther (Just $ show n)
|
||||
|
|
|
@ -315,7 +315,7 @@ parseCfg defcfg = go [] defcfg . lines
|
|||
in Right $ cfg { cfgGlobalConfigs = m }
|
||||
| setting == "numcopies" = case readish val of
|
||||
Nothing -> Left "parse error (expected an integer)"
|
||||
Just n -> Right $ cfg { cfgNumCopies = Just (NumCopies n) }
|
||||
Just n -> Right $ cfg { cfgNumCopies = Just (configuredNumCopies n) }
|
||||
| otherwise = badval "setting" setting
|
||||
where
|
||||
u = toUUID f
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue