remove optimize subcommand; use --auto instead
get, drop: Added --auto option, which decides whether to get/drop content as needed to work toward the configured numcopies. The problem with bundling it up in optimize was that I then found I wanted to run an optmize that did not drop files, only got them. Considered adding a --only-get switch to it, but that seemed wrong. Instead, let's make existing subcommands optionally smarter. Note that the only actual difference between drop and drop --auto is that the latter does not even try to drop a file if it knows of not enough copies, and does not print any error messages about files it was unable to drop. It might be nice to make get avoid asking git for attributes when not in auto mode. For now it always asks for attributes.
This commit is contained in:
parent
81984e60ac
commit
984c9fc052
13 changed files with 92 additions and 78 deletions
19
Command.hs
19
Command.hs
|
@ -26,6 +26,9 @@ import qualified Git
|
|||
import qualified Git.LsFiles as LsFiles
|
||||
import Utility
|
||||
import Types.Key
|
||||
import Trust
|
||||
import LocationLog
|
||||
import Config
|
||||
|
||||
{- A command runs in four stages.
|
||||
-
|
||||
|
@ -276,3 +279,19 @@ preserveOrder orig new = collect orig new
|
|||
-}
|
||||
runPreserveOrder :: ([FilePath] -> IO [FilePath]) -> [FilePath] -> IO [FilePath]
|
||||
runPreserveOrder a files = preserveOrder files <$> a files
|
||||
|
||||
{- Used for commands that have an auto mode that checks the number of known
|
||||
- copies of a key.
|
||||
-
|
||||
- In auto mode, first checks that the number of known
|
||||
- copies of the key is > or < than the numcopies setting, before running
|
||||
- the action. -}
|
||||
autoCopies :: Key -> (Int -> Int -> Bool) -> Maybe Int -> CommandStart -> CommandStart
|
||||
autoCopies key vs numcopiesattr a = do
|
||||
auto <- Annex.getState Annex.auto
|
||||
if auto
|
||||
then do
|
||||
needed <- getNumCopies numcopiesattr
|
||||
(_, have) <- trustPartition UnTrusted =<< keyLocations key
|
||||
if length have `vs` needed then a else stop
|
||||
else a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue