From: Tobias Ulmer Date: Wed, 2 Nov 2016 15:06:44 +0000 (+0100) Subject: cache: writeback() doesn't need to be visible X-Git-Tag: e2factory-2.3.15rc1~25 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=ab86a0a6eec49994af5578e6de662f6871ad0ed8;p=e2factory.git cache: writeback() doesn't need to be visible Signed-off-by: Tobias Ulmer --- diff --git a/generic/cache.lua b/generic/cache.lua index 58399da..b97512e 100644 --- a/generic/cache.lua +++ b/generic/cache.lua @@ -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