summaryrefslogtreecommitdiff
path: root/Command/Drop.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-03-25 17:06:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-03-25 17:06:14 -0400
commit850241b7fed075c8a0055ae77cb30d6485aaa795 (patch)
treebbae2d577ea7daf136cfb80cdf87e4ce76681f84 /Command/Drop.hs
parent644cd4ca27e410ca567ec0f78acf2517d91d330e (diff)
--auto is no longer a global option; only get, drop, and copy accept it.
Not a behavior change unless you were passing it to a command that ignored it.
Diffstat (limited to 'Command/Drop.hs')
-rw-r--r--Command/Drop.hs40
1 files changed, 22 insertions, 18 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 35c2f5cf4..63b9ccb7f 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -27,7 +27,7 @@ cmd = [withOptions (dropOptions) $ command "drop" paramPaths seek
SectionCommon "indicate content of files not currently wanted"]
dropOptions :: [Option]
-dropOptions = dropFromOption : annexedMatchingOptions
+dropOptions = dropFromOption : annexedMatchingOptions ++ [autoOption]
dropFromOption :: Option
dropFromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"
@@ -35,11 +35,12 @@ dropFromOption = fieldOption ['f'] "from" paramRemote "drop content from a remot
seek :: CommandSeek
seek ps = do
from <- getOptionField dropFromOption Remote.byNameWithUUID
- withFilesInGit (whenAnnexed $ start from) ps
+ auto <- getOptionFlag autoOption
+ withFilesInGit (whenAnnexed $ start auto from) ps
-start :: Maybe Remote -> FilePath -> Key -> CommandStart
-start from file key = checkDropAuto from file key $ \numcopies ->
- stopUnless (checkAuto $ wantDrop False (Remote.uuid <$> from) (Just key) (Just file)) $
+start :: Bool -> Maybe Remote -> FilePath -> Key -> CommandStart
+start auto from file key = checkDropAuto auto from file key $ \numcopies ->
+ stopUnless want $
case from of
Nothing -> startLocal (Just file) numcopies key Nothing
Just remote -> do
@@ -47,6 +48,10 @@ start from file key = checkDropAuto from file key $ \numcopies ->
if Remote.uuid remote == u
then startLocal (Just file) numcopies key Nothing
else startRemote (Just file) numcopies key remote
+ where
+ want
+ | auto = wantDrop False (Remote.uuid <$> from) (Just key) (Just file)
+ | otherwise = return True
startLocal :: AssociatedFile -> NumCopies -> Key -> Maybe Remote -> CommandStart
startLocal afile numcopies key knownpresentremote = stopUnless (inAnnex key) $ do
@@ -182,17 +187,16 @@ requiredContent = do
{- In auto mode, only runs the action if there are enough
- copies on other semitrusted repositories. -}
-checkDropAuto :: Maybe Remote -> FilePath -> Key -> (NumCopies -> CommandStart) -> CommandStart
-checkDropAuto mremote file key a = do
- numcopies <- getFileNumCopies file
- Annex.getState Annex.auto >>= auto numcopies
+checkDropAuto :: Bool -> Maybe Remote -> FilePath -> Key -> (NumCopies -> CommandStart) -> CommandStart
+checkDropAuto auto mremote file key a = go =<< getFileNumCopies file
where
- auto numcopies False = a numcopies
- auto numcopies True = do
- locs <- Remote.keyLocations key
- uuid <- getUUID
- let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote
- locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs
- if NumCopies (length locs') >= numcopies
- then a numcopies
- else stop
+ go numcopies
+ | auto = do
+ locs <- Remote.keyLocations key
+ uuid <- getUUID
+ let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote
+ locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs
+ if NumCopies (length locs') >= numcopies
+ then a numcopies
+ else stop
+ | otherwise = a numcopies