From 05a529a171ddbcc3ebded4284021912db59714b1 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Fri, 23 Oct 2009 11:22:29 +0200 Subject: [PATCH] Implement cache and transport flag for internal use: try_hardlink transport.push_file() tries to optimize by creating a hardlink before falling back to copying if that fails. Signed-off-by: Gordon Hecker --- generic/cache.lua | 10 ++++++---- generic/transport.lua | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/generic/cache.lua b/generic/cache.lua index c5caf81..5e11357 100644 --- a/generic/cache.lua +++ b/generic/cache.lua @@ -309,8 +309,8 @@ function push_file(cache, sourcefile, server, location, flags) -- cache is enabled: -- push the file from source to cache and from cache to -- destination - rc, re = transport.push_file(sourcefile, ce.cache_url, location, - nil) + rc, re = transport.push_file(sourcefile, ce.cache_url, + location, nil, flags.try_hardlink) if not rc then return false, e:cat(re) end @@ -322,7 +322,8 @@ function push_file(cache, sourcefile, server, location, flags) -- cache is disabled -- push the file from source to destination immediately rc, re = transport.push_file(sourcefile, ce.remote_url, - location, ce.flags.push_permissions) + location, ce.flags.push_permissions, + flags.try_hardlink) if not rc then return false, e:cat(re) end @@ -355,7 +356,8 @@ function writeback(cache, server, location, flags) end local sourcefile = string.format("/%s/%s", ceurl.path, location) rc, re = transport.push_file(sourcefile, ce.remote_url, location, - ce.flags.push_permissions) + ce.flags.push_permissions, + flags.try_hardlink) if not rc then return false, e:cat(re) end diff --git a/generic/transport.lua b/generic/transport.lua index a2258c1..191f43b 100644 --- a/generic/transport.lua +++ b/generic/transport.lua @@ -205,9 +205,10 @@ end -- @param location location relative to the server url -- @param push_permissions string: permissions to use on the destination -- side. Works with rsync+ssh only. +-- @param try_hardlink bool: optimize by trying to hardlink instead of copying -- @return true on success, false on error -- @return nil, an error string on error -function push_file(sourcefile, durl, location, push_permissions) +function push_file(sourcefile, durl, location, push_permissions, try_hardlink) e2lib.log(4, string.format("%s: %s %s %s %s", "transport.push_file()", sourcefile, durl, location, tostring(push_permissions))) local rc, e @@ -240,9 +241,22 @@ function push_file(sourcefile, durl, location, push_permissions) end local args = string.format("%s '%s' '%s/%s'", rsync_perm, sourcefile, destdir, destname) - rc, re = e2lib.rsync(args) - if not rc then - return false, re + local done = false + if (not push_permissions) and try_hardlink then + local dst = string.format("%s/%s", destdir, destname) + rc, re = e2lib.ln(sourcefile, dst, "--force") + if rc then + done = true + else + e2lib.logf(4, "Creating hardlink failed. ".. + "Falling back to copying.") + end + end + if not done then + rc, re = e2lib.rsync(args) + if not rc then + return false, re + end end elseif u.transport == "rsync+ssh" then local destdir = string.format("/%s", e2lib.dirname(u.path)) -- 2.39.5