]> git.e2factory.org Git - e2factory.git/commitdiff
cache: add invalidate() method
authorTobias Ulmer <tu@emlix.com>
Tue, 28 Jun 2022 08:05:11 +0000 (10:05 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 31 Aug 2022 22:22:17 +0000 (00:22 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/cache.lua

index df1e8648efcc824ac010711ce495c7e4295a5437..829439b4a11c11fd31ce603136eec2fe8cdbb24d 100644 (file)
@@ -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)