From 54305c4a494a716b46a8c57004f79b77b4683a61 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 28 Jun 2022 10:05:11 +0200 Subject: [PATCH] cache: add invalidate() method Signed-off-by: Tobias Ulmer --- generic/cache.lua | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/generic/cache.lua b/generic/cache.lua index df1e864..829439b 100644 --- a/generic/cache.lua +++ b/generic/cache.lua @@ -1,7 +1,7 @@ --- Cache -- @module generic.cache --- Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS +-- Copyright (C) 2007-2022 emlix GmbH, see file AUTHORS -- -- This file is part of e2factory, the emlix embedded build system. -- For more information see http://www.e2factory.org @@ -484,6 +484,44 @@ function cache.islocal_enabled(c, server, flags) return false end +--- Remove file from cache, thus invalidating the entry +-- @param c cache table +-- @param server server name +-- @param location location relative to server +-- @param flags optional cache flags +-- @return True if entry doesn't exists or invalidation was successful, false on error +-- @return Error object on error +function cache.invalidate(c, server, location, flags) + assertIsTable(c) + assertIsStringN(server) + assertIsStringN(location) + flags = verify_optional_flags(flags) + + if not cache.cache_enabled(c, server, flags) then + return true + end + + local ce, re = cache.ce_by_server(c, server) + if not ce then + return false, re + end + + local ceurl, re = url.parse(ce.cache_url) + if not ceurl then + return false, re + end + + local cf = e2lib.join("/", ceurl.path, location) + local rc, re = e2lib.lstat(cf) + if rc then + rc, re = e2lib.unlink(cf) + if not rc then + return false, re + end + end + return true +end + local function file_is_local(c, server, location, flags) assertIsTable(c) -- 2.39.5