]> git.e2factory.org Git - e2factory.git/commitdiff
Implement cache and transport flag for internal use: try_hardlink
authorGordon Hecker <gh@emlix.com>
Fri, 23 Oct 2009 09:22:29 +0000 (11:22 +0200)
committerGordon Hecker <gh@emlix.com>
Fri, 23 Oct 2009 09:29:41 +0000 (11:29 +0200)
transport.push_file() tries to optimize by creating a hardlink before
falling back to copying if that fails.

Signed-off-by: Gordon Hecker <gh@emlix.com>
generic/cache.lua
generic/transport.lua

index c5caf813e7fd56034fbf76c860eb973c17068c86..5e113579a8b6fe5d7f9a45f39e0cc1fc521f5eaa 100644 (file)
@@ -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
index a2258c1d16de2cfb36bec84678c036b99ad572e7..191f43bb0d7820adcaa25f0b49a8330e6b3f466e 100644 (file)
@@ -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))