-- 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
-- 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
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
-- @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
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))