summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-21 17:08:49 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-21 17:25:39 -0400
commitd44bd607d4fd18eadabe3c7693ebcf1c74aae63e (patch)
tree83e8867f45199ece960fc67e4d31f1d9b4a5d56a /Command
parentd5f7fb27aad3e2e9c4bebb9ccd5577af8deb25c7 (diff)
numcopies cleanup, part 2
This includes several bug fixes.
Diffstat (limited to 'Command')
-rw-r--r--Command/Drop.hs38
-rw-r--r--Command/DropUnused.hs17
-rw-r--r--Command/Fsck.hs11
-rw-r--r--Command/Mirror.hs19
-rw-r--r--Command/NumCopies.hs4
5 files changed, 44 insertions, 45 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 9609cf830..8f7e1aae9 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -43,17 +43,17 @@ start from file (key, _) = checkDropAuto from file key $ \numcopies ->
then startLocal (Just file) numcopies key Nothing
else startRemote (Just file) numcopies key remote
-startLocal :: AssociatedFile -> Maybe NumCopies -> Key -> Maybe Remote -> CommandStart
+startLocal :: AssociatedFile -> NumCopies -> Key -> Maybe Remote -> CommandStart
startLocal afile numcopies key knownpresentremote = stopUnless (inAnnex key) $ do
showStart "drop" (fromMaybe (key2file key) afile)
next $ performLocal key numcopies knownpresentremote
-startRemote :: AssociatedFile -> Maybe NumCopies -> Key -> Remote -> CommandStart
+startRemote :: AssociatedFile -> NumCopies -> Key -> Remote -> CommandStart
startRemote afile numcopies key remote = do
showStart ("drop " ++ Remote.name remote) (fromMaybe (key2file key) afile)
next $ performRemote key numcopies remote
-performLocal :: Key -> Maybe NumCopies -> Maybe Remote -> CommandPerform
+performLocal :: Key -> NumCopies -> Maybe Remote -> CommandPerform
performLocal key numcopies knownpresentremote = lockContent key $ do
(remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key
let trusteduuids' = case knownpresentremote of
@@ -65,7 +65,7 @@ performLocal key numcopies knownpresentremote = lockContent key $ do
removeAnnex key
next $ cleanupLocal key
-performRemote :: Key -> Maybe NumCopies -> Remote -> CommandPerform
+performRemote :: Key -> NumCopies -> Remote -> CommandPerform
performRemote key numcopies remote = lockContent key $ do
-- Filter the remote it's being dropped from out of the lists of
-- places assumed to have the key, and places to check.
@@ -98,14 +98,12 @@ cleanupRemote key remote ok = do
{- Checks specified remotes to verify that enough copies of a key exist to
- allow it to be safely removed (with no data loss). Can be provided with
- some locations where the key is known/assumed to be present. -}
-canDropKey :: Key -> Maybe NumCopies -> [UUID] -> [Remote] -> [UUID] -> Annex Bool
-canDropKey key numcopiesM have check skip = do
+canDropKey :: Key -> NumCopies -> [UUID] -> [Remote] -> [UUID] -> Annex Bool
+canDropKey key numcopies have check skip = do
force <- Annex.getState Annex.force
- if force || numcopiesM == Just (NumCopies 0)
+ if force || numcopies == NumCopies 0
then return True
- else do
- need <- getNumCopies numcopiesM
- findCopies key need skip have check
+ else findCopies key numcopies skip have check
findCopies :: Key -> NumCopies -> [UUID] -> [UUID] -> [Remote] -> Annex Bool
findCopies key need skip = helper [] []
@@ -142,22 +140,18 @@ notEnoughCopies key need have skip bad = do
hint = showLongNote "(Use --force to override this check, or adjust numcopies.)"
{- In auto mode, only runs the action if there are enough
- - 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 NumCopies -> CommandStart) -> CommandStart
+ - copies on other semitrusted repositories. -}
+checkDropAuto :: Maybe Remote -> FilePath -> Key -> (NumCopies -> CommandStart) -> CommandStart
checkDropAuto mremote file key a = do
- numcopiesattr <- getFileNumCopies file
- Annex.getState Annex.auto >>= auto numcopiesattr
+ numcopies <- getFileNumCopies file
+ Annex.getState Annex.auto >>= auto numcopies
where
- auto numcopiesattr False = a numcopiesattr
- auto numcopiesattr True = do
- needed <- getNumCopies numcopiesattr
+ 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') >= needed
- then a numcopiesattr
+ if NumCopies (length locs') >= numcopies
+ then a numcopies
else stop
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs
index 5d7c5c1d2..043ddfe00 100644
--- a/Command/DropUnused.hs
+++ b/Command/DropUnused.hs
@@ -15,6 +15,7 @@ import qualified Remote
import qualified Git
import qualified Option
import Command.Unused (withUnusedMaps, UnusedMaps(..), startUnused)
+import Logs.NumCopies
def :: [Command]
def = [withOptions [Command.Drop.fromOption] $
@@ -22,18 +23,20 @@ def = [withOptions [Command.Drop.fromOption] $
seek SectionMaintenance "drop unused file content"]
seek :: CommandSeek
-seek = withUnusedMaps start
+seek ps = do
+ numcopies <- getNumCopies
+ withUnusedMaps (start numcopies) ps
-start :: UnusedMaps -> Int -> CommandStart
-start = startUnused "dropunused" perform (performOther gitAnnexBadLocation) (performOther gitAnnexTmpLocation)
+start :: NumCopies -> UnusedMaps -> Int -> CommandStart
+start numcopies = startUnused "dropunused" (perform numcopies) (performOther gitAnnexBadLocation) (performOther gitAnnexTmpLocation)
-perform :: Key -> CommandPerform
-perform key = maybe droplocal dropremote =<< Remote.byNameWithUUID =<< from
+perform :: NumCopies -> Key -> CommandPerform
+perform numcopies key = maybe droplocal dropremote =<< Remote.byNameWithUUID =<< from
where
dropremote r = do
showAction $ "from " ++ Remote.name r
- Command.Drop.performRemote key Nothing r
- droplocal = Command.Drop.performLocal key Nothing Nothing
+ Command.Drop.performRemote key numcopies r
+ droplocal = Command.Drop.performLocal key numcopies Nothing
from = Annex.getField $ Option.name Command.Drop.fromOption
performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 839ab1d71..598025189 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -119,7 +119,7 @@ start from inc file (key, backend) = do
where
go = runFsck inc file key
-perform :: Key -> FilePath -> Backend -> Maybe NumCopies -> Annex Bool
+perform :: Key -> FilePath -> Backend -> NumCopies -> Annex Bool
perform key file backend numcopies = check
-- order matters
[ fixLink key file
@@ -133,7 +133,7 @@ perform key file backend numcopies = check
{- To fsck a remote, the content is retrieved to a tmp file,
- and checked locally. -}
-performRemote :: Key -> FilePath -> Backend -> Maybe NumCopies -> Remote -> Annex Bool
+performRemote :: Key -> FilePath -> Backend -> NumCopies -> Remote -> Annex Bool
performRemote key file backend numcopies remote =
dispatch =<< Remote.hasKey remote key
where
@@ -369,15 +369,14 @@ checkBackendOr' bad backend key file postcheck =
, return True
)
-checkKeyNumCopies :: Key -> FilePath -> Maybe NumCopies -> Annex Bool
+checkKeyNumCopies :: Key -> FilePath -> NumCopies -> Annex Bool
checkKeyNumCopies key file numcopies = do
- needed <- getNumCopies numcopies
(untrustedlocations, safelocations) <- trustPartition UnTrusted =<< Remote.keyLocations key
let present = NumCopies (length safelocations)
- if present < needed
+ if present < numcopies
then do
ppuuids <- Remote.prettyPrintUUIDs "untrusted" untrustedlocations
- warning $ missingNote file present needed ppuuids
+ warning $ missingNote file present numcopies ppuuids
return False
else return True
diff --git a/Command/Mirror.hs b/Command/Mirror.hs
index e5ce33ec0..fb06ed2b4 100644
--- a/Command/Mirror.hs
+++ b/Command/Mirror.hs
@@ -28,17 +28,15 @@ seek ps = do
to <- getOptionField toOption Remote.byNameWithUUID
from <- getOptionField fromOption Remote.byNameWithUUID
withKeyOptions
- (startKey Nothing to from Nothing)
+ (startKey to from Nothing)
(withFilesInGit $ whenAnnexed $ start to from)
ps
start :: Maybe Remote -> Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
-start to from file (key, _backend) = do
- numcopies <- getFileNumCopies file
- startKey numcopies to from (Just file) key
+start to from file (key, _backend) = startKey to from (Just file) key
-startKey :: Maybe NumCopies -> Maybe Remote -> Maybe Remote -> Maybe FilePath -> Key -> CommandStart
-startKey numcopies to from afile key = do
+startKey :: Maybe Remote -> Maybe Remote -> Maybe FilePath -> Key -> CommandStart
+startKey to from afile key = do
noAuto
case (from, to) of
(Nothing, Nothing) -> error "specify either --from or --to"
@@ -50,7 +48,9 @@ startKey numcopies to from afile key = do
error "--auto is not supported for mirror"
mirrorto r = ifM (inAnnex key)
( Command.Move.toStart r False afile key
- , Command.Drop.startRemote afile numcopies key r
+ , do
+ numcopies <- getnumcopies
+ Command.Drop.startRemote afile numcopies key r
)
mirrorfrom r = do
haskey <- Remote.hasKey r key
@@ -58,6 +58,9 @@ startKey numcopies to from afile key = do
Left _ -> stop
Right True -> Command.Get.start' (return True) Nothing key afile
Right False -> ifM (inAnnex key)
- ( Command.Drop.startLocal afile numcopies key Nothing
+ ( do
+ numcopies <- getnumcopies
+ Command.Drop.startLocal afile numcopies key Nothing
, stop
)
+ getnumcopies = maybe getNumCopies getFileNumCopies afile
diff --git a/Command/NumCopies.hs b/Command/NumCopies.hs
index 51bde2e68..cc322bcbd 100644
--- a/Command/NumCopies.hs
+++ b/Command/NumCopies.hs
@@ -42,10 +42,10 @@ startGet = next $ next $ do
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
Nothing -> do
liftIO $ putStrLn $ "global numcopies is not set"
- old <- annexNumCopies <$> Annex.getGitConfig
+ old <- deprecatedNumCopies
case old of
Nothing -> liftIO $ putStrLn "(default is 1)"
- Just n -> liftIO $ putStrLn $ "(deprecated git config annex.numcopies is set to " ++ show n ++ " locally)"
+ Just n -> liftIO $ putStrLn $ "(deprecated git config annex.numcopies is set to " ++ show (fromNumCopies n) ++ " locally)"
return True
startSet :: Int -> CommandStart