summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-15 13:42:41 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-15 13:42:41 -0400
commite26746760639a6e6b8f072941f7f2c52efa11c25 (patch)
tree42bc733d2037dd9c6d67ada8a7ae43a3ab07f48c
parent11ea080a627b7eea17d5a931ae855cdb30144cdc (diff)
optimise sending to encrypted rsync
With an encrypted rsync remote, the encrpyted file can be renamed, rather than being copied, in crippled filesystem mode. This gets back to just as fast as non-crippled mode for this very common case.
-rw-r--r--Remote/Rsync.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/Remote/Rsync.hs b/Remote/Rsync.hs
index 7ce0e69b6..51e8b6ab7 100644
--- a/Remote/Rsync.hs
+++ b/Remote/Rsync.hs
@@ -102,14 +102,14 @@ rsyncUrls o k = map use annexHashes
f = keyFile k
store :: RsyncOpts -> Key -> AssociatedFile -> MeterUpdate -> Annex Bool
-store o k _f p = sendAnnex k (void $ remove o k) $ rsyncSend o p k
+store o k _f p = sendAnnex k (void $ remove o k) $ rsyncSend o p k False
storeEncrypted :: RsyncOpts -> (Cipher, Key) -> Key -> MeterUpdate -> Annex Bool
storeEncrypted o (cipher, enck) k p = withTmp enck $ \tmp ->
sendAnnex k (void $ remove o enck) $ \src -> do
liftIO $ encrypt cipher (feedFile src) $
readBytes $ L.writeFile tmp
- rsyncSend o p enck tmp
+ rsyncSend o p enck True tmp
retrieve :: RsyncOpts -> Key -> AssociatedFile -> FilePath -> Annex Bool
retrieve o k _ f = untilTrue (rsyncUrls o k) $ \u -> rsyncRemote o Nothing
@@ -216,16 +216,18 @@ rsyncRemote o callback params = do
- (When we have the right hash directory structure, we can just
- pass --include=X --include=X/Y --include=X/Y/file --exclude=*)
-}
-rsyncSend :: RsyncOpts -> MeterUpdate -> Key -> FilePath -> Annex Bool
-rsyncSend o callback k src = withRsyncScratchDir $ \tmp -> do
+rsyncSend :: RsyncOpts -> MeterUpdate -> Key -> Bool -> FilePath -> Annex Bool
+rsyncSend o callback k canrename src = withRsyncScratchDir $ \tmp -> do
let dest = tmp </> Prelude.head (keyPaths k)
liftIO $ createDirectoryIfMissing True $ parentDir dest
- ok <- ifM crippledFileSystem
- ( liftIO $ copyFileExternal src dest
- , do
- liftIO $ createLink src dest
- return True
- )
+ ok <- if canrename
+ then liftIO $ renameFile src dest
+ else ifM crippledFileSystem
+ ( liftIO $ copyFileExternal src dest
+ , do
+ liftIO $ createLink src dest
+ return True
+ )
if ok
then rsyncRemote o (Just callback)
[ Param "--recursive"