hook rsync special remote up to the progress reporting

Easy!

Note that with an encrypted remote, rsync will be sending a little more
data than the key size, so displayed progress may get to 100% slightly
quicker than it should. I doubt this is a big enough effect to worry about.
This commit is contained in:
Joey Hess 2012-09-20 13:50:21 -04:00
parent 66d092dc7c
commit 2ae38325d5
2 changed files with 11 additions and 10 deletions

View file

@ -105,16 +105,16 @@ rsyncUrls o k = map use annexHashes
f = keyFile k f = keyFile k
store :: RsyncOpts -> Key -> AssociatedFile -> ProgressCallback -> Annex Bool store :: RsyncOpts -> Key -> AssociatedFile -> ProgressCallback -> Annex Bool
store o k _f p = rsyncSend o k <=< inRepo $ gitAnnexLocation k store o k _f p = rsyncSend o p k <=< inRepo $ gitAnnexLocation k
storeEncrypted :: RsyncOpts -> (Cipher, Key) -> Key -> ProgressCallback -> Annex Bool storeEncrypted :: RsyncOpts -> (Cipher, Key) -> Key -> ProgressCallback -> Annex Bool
storeEncrypted o (cipher, enck) k p = withTmp enck $ \tmp -> do storeEncrypted o (cipher, enck) k p = withTmp enck $ \tmp -> do
src <- inRepo $ gitAnnexLocation k src <- inRepo $ gitAnnexLocation k
liftIO $ withEncryptedContent cipher (L.readFile src) $ L.writeFile tmp liftIO $ withEncryptedContent cipher (L.readFile src) $ L.writeFile tmp
rsyncSend o enck tmp rsyncSend o p enck tmp
retrieve :: RsyncOpts -> Key -> AssociatedFile -> FilePath -> Annex Bool retrieve :: RsyncOpts -> Key -> AssociatedFile -> FilePath -> Annex Bool
retrieve o k _ f = untilTrue (rsyncUrls o k) $ \u -> rsyncRemote o retrieve o k _ f = untilTrue (rsyncUrls o k) $ \u -> rsyncRemote o Nothing
-- use inplace when retrieving to support resuming -- use inplace when retrieving to support resuming
[ Param "--inplace" [ Param "--inplace"
, Param u , Param u
@ -191,10 +191,10 @@ withRsyncScratchDir a = do
nuke d = liftIO $ whenM (doesDirectoryExist d) $ nuke d = liftIO $ whenM (doesDirectoryExist d) $
removeDirectoryRecursive d removeDirectoryRecursive d
rsyncRemote :: RsyncOpts -> [CommandParam] -> Annex Bool rsyncRemote :: RsyncOpts -> (Maybe ProgressCallback) -> [CommandParam] -> Annex Bool
rsyncRemote o params = do rsyncRemote o callback params = do
showOutput -- make way for progress bar showOutput -- make way for progress bar
ifM (liftIO $ rsync $ rsyncOptions o ++ defaultParams ++ params) ifM (liftIO $ (maybe rsync rsyncProgress callback) ps)
( return True ( return True
, do , do
showLongNote "rsync failed -- run git annex again to resume file transfer" showLongNote "rsync failed -- run git annex again to resume file transfer"
@ -202,16 +202,17 @@ rsyncRemote o params = do
) )
where where
defaultParams = [Params "--progress"] defaultParams = [Params "--progress"]
ps = rsyncOptions o ++ defaultParams ++ params
{- To send a single key is slightly tricky; need to build up a temporary {- To send a single key is slightly tricky; need to build up a temporary
directory structure to pass to rsync so it can create the hash directory structure to pass to rsync so it can create the hash
directories. -} directories. -}
rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool rsyncSend :: RsyncOpts -> ProgressCallback -> Key -> FilePath -> Annex Bool
rsyncSend o k src = withRsyncScratchDir $ \tmp -> do rsyncSend o callback k src = withRsyncScratchDir $ \tmp -> do
let dest = tmp </> Prelude.head (keyPaths k) let dest = tmp </> Prelude.head (keyPaths k)
liftIO $ createDirectoryIfMissing True $ parentDir dest liftIO $ createDirectoryIfMissing True $ parentDir dest
liftIO $ createLink src dest liftIO $ createLink src dest
rsyncRemote o rsyncRemote o (Just callback)
[ Param "--recursive" [ Param "--recursive"
, partialParams , partialParams
-- tmp/ to send contents of tmp dir -- tmp/ to send contents of tmp dir

View file

@ -23,7 +23,7 @@ the ProgressCallback as the upload progresses.
--server --sender` and in that mode it does not report progress info. --server --sender` and in that mode it does not report progress info.
So downloads initiated by other repos do not show progress in the repo So downloads initiated by other repos do not show progress in the repo
doing the uploading. doing the uploading.
* rsync * rsync: **done**
* directory * directory
* web: Not applicable; does not upload * web: Not applicable; does not upload
* S3 * S3