]> git.e2factory.org Git - e2factory.git/commitdiff
cache: writeback() doesn't need to be visible
authorTobias Ulmer <tu@emlix.com>
Wed, 2 Nov 2016 15:06:44 +0000 (16:06 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/cache.lua

index 58399dafac2d5efd06838cc3d315020d185c30c5..b97512ee02d49621761e51b578bcdcbdad8e75c8 100644 (file)
@@ -667,6 +667,41 @@ function cache.file_exists(c, server, location, flags)
     return rc
 end
 
+--- writeback a cached file
+-- @param c the cache data structure
+-- @param server Server to write the file back to.
+-- @param location Path to the file in cache and on the server.
+-- @param flags
+-- @return bool
+-- @return an error object on failure
+local function cache_writeback(c, server, location, flags)
+    local e = err.new("writeback failed")
+    local rc, re
+    assertFlags(flags)
+
+    local ce, re = cache.ce_by_server(c, server)
+    if not ce then
+        return false, e:cat(re)
+    end
+
+    local ceurl, re = url.parse(ce.cache_url)
+    if not ceurl then
+        return false, e:cat(re)
+    end
+
+    if cache.writeback_enabled(c, server, flags) == false then
+        return true
+    end
+
+    local sourcefile = string.format("/%s/%s", ceurl.path, location)
+    rc, re = transport.push_file(sourcefile, ce.remote_url, location,
+        ce.flags.push_permissions, flags.try_hardlink)
+    if not rc then
+        return false, e:cat(re)
+    end
+    return true
+end
+
 --- push a file to a server: cache and writeback
 -- @param c a cache table
 -- @param sourcefile where to store the file locally
@@ -696,7 +731,7 @@ function cache.push_file(c, sourcefile, server, location, flags)
             return false, e:cat(re)
         end
 
-        rc, re = cache.writeback(c, server, location, flags)
+        rc, re = cache_writeback(c, server, location, flags)
         if not rc then
             return false, e:cat(re)
         end
@@ -741,41 +776,6 @@ function cache.writeback_enabled(c, server, flags)
     return true
 end
 
---- writeback a cached file
--- @param c the cache data structure
--- @param server Server to write the file back to.
--- @param location Path to the file in cache and on the server.
--- @param flags
--- @return bool
--- @return an error object on failure
-function cache.writeback(c, server, location, flags)
-    local e = err.new("writeback failed")
-    local rc, re
-    assertFlags(flags)
-
-    local ce, re = cache.ce_by_server(c, server)
-    if not ce then
-        return false, e:cat(re)
-    end
-
-    local ceurl, re = url.parse(ce.cache_url)
-    if not ceurl then
-        return false, e:cat(re)
-    end
-
-    if cache.writeback_enabled(c, server, flags) == false then
-        return true
-    end
-
-    local sourcefile = string.format("/%s/%s", ceurl.path, location)
-    rc, re = transport.push_file(sourcefile, ce.remote_url, location,
-        ce.flags.push_permissions, flags.try_hardlink)
-    if not rc then
-        return false, e:cat(re)
-    end
-    return true
-end
-
 --- enable/disable writeback for a server
 -- @param c the cache data structure
 -- @param server the server where the file is located