make copy --to check preferred content of the remote
This commit is contained in:
parent
17543f6e80
commit
1eedf495c3
5 changed files with 73 additions and 39 deletions
50
Annex/Wanted.hs
Normal file
50
Annex/Wanted.hs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
{- git-annex control over whether content is wanted
|
||||||
|
-
|
||||||
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Annex.Wanted where
|
||||||
|
|
||||||
|
import Common.Annex
|
||||||
|
import qualified Remote
|
||||||
|
import Annex.Content
|
||||||
|
import Logs.PreferredContent
|
||||||
|
import Git.FilePath
|
||||||
|
import qualified Annex
|
||||||
|
import Annex.UUID
|
||||||
|
|
||||||
|
import qualified Data.Set as S
|
||||||
|
|
||||||
|
checkAuto :: (Bool -> Annex Bool) -> Annex Bool
|
||||||
|
checkAuto a = Annex.getState Annex.auto >>= a
|
||||||
|
|
||||||
|
{- A file's content should be gotten if it's not already present.
|
||||||
|
- In auto mode, only get files that are preferred content. -}
|
||||||
|
shouldGet :: FilePath -> Key -> Bool -> Annex Bool
|
||||||
|
shouldGet file key auto = (not <$> inAnnex key) <&&> want
|
||||||
|
where
|
||||||
|
want
|
||||||
|
| auto = do
|
||||||
|
fp <- inRepo $ toTopFilePath file
|
||||||
|
isPreferredContent Nothing S.empty fp
|
||||||
|
| otherwise = return True
|
||||||
|
|
||||||
|
{- A file's content should be sent to a remote.
|
||||||
|
- In auto mode, only send files that are preferred content of the remote. -}
|
||||||
|
shouldSend :: Remote -> FilePath -> Bool -> Annex Bool
|
||||||
|
shouldSend _ _ False = return True
|
||||||
|
shouldSend to file True = do
|
||||||
|
fp <- inRepo $ toTopFilePath file
|
||||||
|
isPreferredContent (Just $ Remote.uuid to) S.empty fp
|
||||||
|
|
||||||
|
{- A file's content should be dropped normally.
|
||||||
|
- (This does not check numcopies though.)
|
||||||
|
- In auto mode, hold on to preferred content. -}
|
||||||
|
shouldDrop :: Maybe Remote -> FilePath -> Bool -> Annex Bool
|
||||||
|
shouldDrop _ _ False = return True
|
||||||
|
shouldDrop from file True = do
|
||||||
|
fp <- inRepo $ toTopFilePath file
|
||||||
|
u <- maybe getUUID (return . Remote.uuid) from
|
||||||
|
isPreferredContent (Just u) (S.singleton u) fp
|
11
Command.hs
11
Command.hs
|
@ -38,10 +38,6 @@ import Usage as ReExported
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
import Config
|
import Config
|
||||||
import Annex.CheckAttr
|
import Annex.CheckAttr
|
||||||
import Logs.PreferredContent
|
|
||||||
import Git.FilePath
|
|
||||||
|
|
||||||
import qualified Data.Set as S
|
|
||||||
|
|
||||||
{- Generates a normal command -}
|
{- Generates a normal command -}
|
||||||
command :: String -> String -> [CommandSeek] -> String -> Command
|
command :: String -> String -> [CommandSeek] -> String -> Command
|
||||||
|
@ -127,12 +123,7 @@ autoCopies file key vs a = Annex.getState Annex.auto >>= go
|
||||||
numcopiesattr <- numCopies file
|
numcopiesattr <- numCopies file
|
||||||
needed <- getNumCopies numcopiesattr
|
needed <- getNumCopies numcopiesattr
|
||||||
(_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
|
(_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
|
||||||
if length have `vs` needed
|
if length have `vs` needed then a else stop
|
||||||
then do
|
|
||||||
fp <- inRepo $ toTopFilePath file
|
|
||||||
ifM (isPreferredContent Nothing S.empty fp)
|
|
||||||
( a, stop )
|
|
||||||
else stop
|
|
||||||
|
|
||||||
autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
|
autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
|
||||||
autoCopiesWith file key vs a = do
|
autoCopiesWith file key vs a = do
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Command.Move
|
import qualified Command.Move
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
|
import Annex.Wanted
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions Command.Move.options $ command "copy" paramPaths seek
|
def = [withOptions Command.Move.options $ command "copy" paramPaths seek
|
||||||
|
@ -21,8 +22,14 @@ seek = [withField Command.Move.toOption Remote.byName $ \to ->
|
||||||
withField Command.Move.fromOption Remote.byName $ \from ->
|
withField Command.Move.fromOption Remote.byName $ \from ->
|
||||||
withFilesInGit $ whenAnnexed $ start to from]
|
withFilesInGit $ whenAnnexed $ start to from]
|
||||||
|
|
||||||
-- A copy is just a move that does not delete the source file.
|
{- A copy is just a move that does not delete the source file.
|
||||||
-- However, --auto mode avoids unnecessary copies.
|
- However, --auto mode avoids unnecessary copies, and avoids getting or
|
||||||
|
- sending non-preferred content. -}
|
||||||
start :: Maybe Remote -> Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
start :: Maybe Remote -> Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start to from file (key, backend) = autoCopies file key (<) $
|
start to from file (key, backend) = autoCopies file key (<) $
|
||||||
Command.Move.start to from False file (key, backend)
|
stopUnless shouldCopy $
|
||||||
|
Command.Move.start to from False file (key, backend)
|
||||||
|
where
|
||||||
|
shouldCopy = case to of
|
||||||
|
Nothing -> checkAuto $ shouldGet file key
|
||||||
|
Just r -> checkAuto $ shouldSend r file
|
||||||
|
|
|
@ -17,10 +17,7 @@ import Logs.Trust
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import Config
|
import Config
|
||||||
import qualified Option
|
import qualified Option
|
||||||
import Git.FilePath
|
import Annex.Wanted
|
||||||
import Logs.PreferredContent
|
|
||||||
|
|
||||||
import qualified Data.Set as S
|
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions [fromOption] $ command "drop" paramPaths seek
|
def = [withOptions [fromOption] $ command "drop" paramPaths seek
|
||||||
|
@ -34,27 +31,15 @@ seek = [withField fromOption Remote.byName $ \from ->
|
||||||
withFilesInGit $ whenAnnexed $ start from]
|
withFilesInGit $ whenAnnexed $ start from]
|
||||||
|
|
||||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start from file (key, _) = shouldDrop $ \numcopies ->
|
start from file (key, _) = autoCopiesWith file key (>) $ \numcopies ->
|
||||||
case from of
|
stopUnless (checkAuto $ shouldDrop from file) $
|
||||||
Nothing -> startLocal file numcopies key
|
case from of
|
||||||
Just remote -> do
|
Nothing -> startLocal file numcopies key
|
||||||
u <- getUUID
|
Just remote -> do
|
||||||
if Remote.uuid remote == u
|
u <- getUUID
|
||||||
then startLocal file numcopies key
|
if Remote.uuid remote == u
|
||||||
else startRemote file numcopies key remote
|
then startLocal file numcopies key
|
||||||
where
|
else startRemote file numcopies key remote
|
||||||
{- In --auto mode, drop if there are enough copies,
|
|
||||||
- and the repository being dropped from doesn't prefer
|
|
||||||
- to keep the content. -}
|
|
||||||
shouldDrop a = autoCopiesWith file key (>) $ \numcopies ->
|
|
||||||
ifM (Annex.getState Annex.auto)
|
|
||||||
( do
|
|
||||||
fp <- inRepo $ toTopFilePath file
|
|
||||||
u <- maybe getUUID (return . Remote.uuid) from
|
|
||||||
ifM (isPreferredContent (Just u) (S.singleton u) fp)
|
|
||||||
( a numcopies, stop )
|
|
||||||
, a numcopies
|
|
||||||
)
|
|
||||||
|
|
||||||
startLocal :: FilePath -> Maybe Int -> Key -> CommandStart
|
startLocal :: FilePath -> Maybe Int -> Key -> CommandStart
|
||||||
startLocal file numcopies key = stopUnless (inAnnex key) $ do
|
startLocal file numcopies key = stopUnless (inAnnex key) $ do
|
||||||
|
|
|
@ -13,6 +13,7 @@ import qualified Remote
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import qualified Command.Move
|
import qualified Command.Move
|
||||||
import Logs.Transfer
|
import Logs.Transfer
|
||||||
|
import Annex.Wanted
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
|
def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
|
||||||
|
@ -23,7 +24,7 @@ seek = [withField Command.Move.fromOption Remote.byName $ \from ->
|
||||||
withFilesInGit $ whenAnnexed $ start from]
|
withFilesInGit $ whenAnnexed $ start from]
|
||||||
|
|
||||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start from file (key, _) = stopUnless (not <$> inAnnex key) $
|
start from file (key, _) = stopUnless (checkAuto $ shouldGet file key) $
|
||||||
autoCopies file key (<) $
|
autoCopies file key (<) $
|
||||||
case from of
|
case from of
|
||||||
Nothing -> go $ perform key file
|
Nothing -> go $ perform key file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue