d266a41f8d
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
53 lines
1.6 KiB
Haskell
53 lines
1.6 KiB
Haskell
{- git-annex command
|
|
-
|
|
- Copyright 2014-2021 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Command.NumCopies where
|
|
|
|
import Command
|
|
import Annex.NumCopies
|
|
|
|
cmd :: Command
|
|
cmd = noMessages $ command "numcopies" SectionSetup
|
|
"configure desired number of copies"
|
|
paramNumber (withParams seek)
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
seek = withWords (commandAction . start)
|
|
|
|
start :: [String] -> CommandStart
|
|
start = start' "numcopies" startGet startSet
|
|
|
|
start' :: String -> CommandStart -> (Int -> CommandStart) -> [String] -> CommandStart
|
|
start' _ startget _ [] = startget
|
|
start' setting _ startset [s] = case readish s of
|
|
Nothing -> giveup $ "Bad number: " ++ s
|
|
Just n
|
|
| n > 0 -> startset n
|
|
| n == 0 -> giveup $ "Cannot set " ++ setting ++ " to 0."
|
|
| otherwise -> giveup $ setting ++ " cannot be negative!"
|
|
start' _ _ _ _ = giveup "Specify a single number."
|
|
|
|
startGet :: CommandStart
|
|
startGet = startingCustomOutput (ActionItemOther Nothing) $ next $ do
|
|
v <- getGlobalNumCopies
|
|
case v of
|
|
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
|
|
Nothing -> do
|
|
liftIO $ putStrLn "global numcopies is not set"
|
|
old <- deprecatedNumCopies
|
|
case old of
|
|
Nothing -> liftIO $ putStrLn "(default is 1)"
|
|
Just n -> liftIO $ putStrLn $ "(deprecated git config annex.numcopies is set to " ++ show (fromNumCopies n) ++ " locally)"
|
|
return True
|
|
|
|
startSet :: Int -> CommandStart
|
|
startSet n = startingUsualMessages "numcopies" ai si $ do
|
|
setGlobalNumCopies $ configuredNumCopies n
|
|
next $ return True
|
|
where
|
|
ai = ActionItemOther (Just $ show n)
|
|
si = SeekInput [show n]
|