From d87af82d97e3f8701b714e48c9ee4e744339d391 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 1 Apr 2013 15:20:42 -0400 Subject: [PATCH] drop --auto: Fix bug that prevented dropping files from untrusted repositories. This is a corresponding bug to the one I fixed yesterday in the assistant. --- Command.hs | 21 --------------------- Command/Drop.hs | 23 ++++++++++++++++++++++- debian/changelog | 2 ++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Command.hs b/Command.hs index 5c1395ed77..06126103b6 100644 --- a/Command.hs +++ b/Command.hs @@ -20,7 +20,6 @@ module Command ( isBareRepo, numCopies, numCopiesCheck, - autoCopiesWith, checkAuto, module ReExported ) where @@ -109,26 +108,6 @@ numCopiesCheck file key vs = do have <- trustExclude UnTrusted =<< Remote.keyLocations key return $ length have `vs` needed -{- 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. - -} -autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart -autoCopiesWith file key vs a = do - numcopiesattr <- numCopies file - Annex.getState Annex.auto >>= auto numcopiesattr - where - auto numcopiesattr False = a numcopiesattr - auto numcopiesattr True = do - needed <- getNumCopies numcopiesattr - have <- trustExclude UnTrusted =<< Remote.keyLocations key - if length have `vs` needed - then a numcopiesattr - else stop - checkAuto :: Annex Bool -> Annex Bool checkAuto checker = ifM (Annex.getState Annex.auto) ( checker , return True ) diff --git a/Command/Drop.hs b/Command/Drop.hs index 4e3a062af4..b3f7d75740 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -31,7 +31,7 @@ seek = [withField fromOption Remote.byNameWithUUID $ \from -> withFilesInGit $ whenAnnexed $ start from] start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart -start from file (key, _) = autoCopiesWith file key (>) $ \numcopies -> +start from file (key, _) = checkDropAuto from file key $ \numcopies -> stopUnless (checkAuto $ wantDrop False (Remote.uuid <$> from) (Just file)) $ case from of Nothing -> startLocal file numcopies key Nothing @@ -138,3 +138,24 @@ notEnoughCopies key need have skip bad = do where unsafe = showNote "unsafe" hint = showLongNote "(Use --force to override this check, or adjust annex.numcopies.)" + +{- In auto mode, only runs the action if there are enough copies + - copies on other semitrusted repositories. + - + - Passes any numcopies attribute of the file on to the action as an + - optimisation. -} +checkDropAuto :: Maybe Remote -> FilePath -> Key -> (Maybe Int -> CommandStart) -> CommandStart +checkDropAuto mremote file key a = do + numcopiesattr <- numCopies file + Annex.getState Annex.auto >>= auto numcopiesattr + where + auto numcopiesattr False = a numcopiesattr + auto numcopiesattr True = do + needed <- getNumCopies numcopiesattr + locs <- Remote.keyLocations key + uuid <- getUUID + let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote + locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs + if length locs' >= needed + then a numcopiesattr + else stop diff --git a/debian/changelog b/debian/changelog index 8b32298713..763e3577f9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,8 @@ git-annex (4.20130324) UNRELEASED; urgency=low * Adjust built-in preferred content expressions to make most types of repositories want content that is only located on untrusted, dead, and unwanted repositories. + * drop --auto: Fix bug that prevented dropping files from untrusted + repositories. -- Joey Hess Mon, 25 Mar 2013 10:21:46 -0400