add tmp flag parameter to retrieveKeyFile

This commit is contained in:
Joey Hess 2012-01-19 16:07:36 -04:00
parent 94aa6b42b5
commit 06b0cb6224
12 changed files with 29 additions and 27 deletions

View file

@ -65,7 +65,7 @@ performRemote key file backend numcopies remote = withTmp key $ \tmpfile -> do
showNote err
stop
Right True -> do
copied <- Remote.retrieveKeyFile remote key tmpfile
copied <- Remote.retrieveKeyFile remote key True tmpfile
if copied then go True (Just tmpfile) else go False Nothing
Right False -> go False Nothing
where

View file

@ -72,7 +72,7 @@ getKeyFile key file = do
else return True
docopy r continue = do
showAction $ "from " ++ Remote.name r
copied <- Remote.retrieveKeyFile r key file
copied <- Remote.retrieveKeyFile r key False file
if copied
then return True
else continue

View file

@ -131,7 +131,7 @@ fromPerform src move key = moveLock move key $ do
then handle move True
else do
showAction $ "from " ++ Remote.name src
ok <- getViaTmp key $ Remote.retrieveKeyFile src key
ok <- getViaTmp key $ Remote.retrieveKeyFile src key False
handle move ok
where
handle _ False = stop -- failed

View file

@ -118,8 +118,8 @@ storeEncrypted r buprepo (cipher, enck) k = do
withEncryptedHandle cipher (L.readFile src) $ \h ->
pipeBup params (Just h) Nothing
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
retrieve buprepo k f = do
retrieve :: BupRepo -> Key -> Bool -> FilePath -> Annex Bool
retrieve buprepo k _ f = do
let params = bupParams "join" buprepo [Param $ show k]
liftIO $ catchBoolIO $ do
tofile <- openFile f WriteMode

View file

@ -109,8 +109,9 @@ storeHelper d key a = do
preventWrite dir
return ok
retrieve :: FilePath -> Key -> FilePath -> Annex Bool
retrieve d k f = liftIO $ withStoredFile d k $ \file -> copyFileExternal file f
retrieve :: FilePath -> Key -> Bool -> FilePath -> Annex Bool
retrieve d k _ f = do
liftIO $ withStoredFile d k $ \file -> copyFileExternal file f
retrieveEncrypted :: FilePath -> (Cipher, Key) -> FilePath -> Annex Bool
retrieveEncrypted d (cipher, enck) f =

View file

@ -198,8 +198,8 @@ dropKey r key
]
{- Tries to copy a key's content from a remote's annex to a file. -}
copyFromRemote :: Git.Repo -> Key -> FilePath -> Annex Bool
copyFromRemote r key file
copyFromRemote :: Git.Repo -> Key -> Bool -> FilePath -> Annex Bool
copyFromRemote r key _ file
| not $ Git.repoIsUrl r = do
params <- rsyncParams r
loc <- liftIO $ gitAnnexLocation key r

View file

@ -55,8 +55,8 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r =
store k = cip k >>= maybe
(storeKey r k)
(`storeKeyEncrypted` k)
retrieve k f = cip k >>= maybe
(retrieveKeyFile r k f)
retrieve k t f = cip k >>= maybe
(retrieveKeyFile r k t f)
(`retrieveKeyFileEncrypted` f)
withkey a k = cip k >>= maybe (a k) (a . snd)
cip = cipherKey c

View file

@ -106,8 +106,8 @@ storeEncrypted h (cipher, enck) k = withTmp enck $ \tmp -> do
liftIO $ withEncryptedContent cipher (L.readFile src) $ L.writeFile tmp
runHook h "store" enck (Just tmp) $ return True
retrieve :: String -> Key -> FilePath -> Annex Bool
retrieve h k f = runHook h "retrieve" k (Just f) $ return True
retrieve :: String -> Key -> Bool -> FilePath -> Annex Bool
retrieve h k _ f = runHook h "retrieve" k (Just f) $ return True
retrieveEncrypted :: String -> (Cipher, Key) -> FilePath -> Annex Bool
retrieveEncrypted h (cipher, enck) f = withTmp enck $ \tmp ->

View file

@ -104,9 +104,9 @@ storeEncrypted o (cipher, enck) k = withTmp enck $ \tmp -> do
liftIO $ withEncryptedContent cipher (L.readFile src) $ L.writeFile tmp
rsyncSend o enck tmp
retrieve :: RsyncOpts -> Key -> FilePath -> Annex Bool
retrieve o k f = untilTrue (rsyncUrls o k) $ \u -> do
unlessM (liftIO $ doesFileExist f) $ whenM (inAnnex k) $ preseed
retrieve :: RsyncOpts -> Key -> Bool -> FilePath -> Annex Bool
retrieve o k tmp f = untilTrue (rsyncUrls o k) $ \u -> do
when tmp $ preseed
rsyncRemote o
-- use inplace when retrieving to support resuming
[ Param "--inplace"
@ -115,14 +115,15 @@ retrieve o k f = untilTrue (rsyncUrls o k) $ \u -> do
]
where
-- this speeds up fsck --from
preseed = do
s <- inRepo $ gitAnnexLocation k
liftIO $ whenM (copyFileExternal s f) $
allowWrite f
preseed = unlessM (liftIO $ doesFileExist f) $
whenM (inAnnex k) $ do
s <- inRepo $ gitAnnexLocation k
liftIO $ whenM (copyFileExternal s f) $
allowWrite f
retrieveEncrypted :: RsyncOpts -> (Cipher, Key) -> FilePath -> Annex Bool
retrieveEncrypted o (cipher, enck) f = withTmp enck $ \tmp -> do
res <- retrieve o enck tmp
res <- retrieve o enck False tmp
if res
then liftIO $ catchBoolIO $ do
withDecryptedContent cipher (L.readFile tmp) $ L.writeFile f

View file

@ -149,8 +149,8 @@ storeHelper (conn, bucket) r k file = do
xheaders = filter isxheader $ M.assocs $ fromJust $ config r
isxheader (h, _) = "x-amz-" `isPrefixOf` h
retrieve :: Remote -> Key -> FilePath -> Annex Bool
retrieve r k f = s3Action r False $ \(conn, bucket) -> do
retrieve :: Remote -> Key -> Bool -> FilePath -> Annex Bool
retrieve r k _ f = s3Action r False $ \(conn, bucket) -> do
res <- liftIO $ getObject conn $ bucketKey r bucket k
case res of
Right o -> do

View file

@ -48,8 +48,8 @@ gen r _ _ =
remotetype = remote
}
downloadKey :: Key -> FilePath -> Annex Bool
downloadKey key file = get =<< getUrls key
downloadKey :: Key -> Bool -> FilePath -> Annex Bool
downloadKey key _ file = get =<< getUrls key
where
get [] = do
warning "no known url"

View file

@ -43,8 +43,8 @@ data RemoteA a = Remote {
cost :: Int,
-- Transfers a key to the remote.
storeKey :: Key -> a Bool,
-- retrieves a key's contents to a file
retrieveKeyFile :: Key -> FilePath -> a Bool,
-- retrieves a key's contents to a file (possibly a tmp file)
retrieveKeyFile :: Key -> Bool -> FilePath -> a Bool,
-- removes a key's contents
removeKey :: Key -> a Bool,
-- Checks if a key is present in the remote; if the remote