From 6e3779be4c0fabaadd6b37c525278b6a6c99593a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 15 Aug 2018 17:31:29 +0200 Subject: [PATCH] cache API: avoid some ENOENT errors --- daemon/lua/sandbox.lua | 2 +- lib/cache/api.c | 8 +++++++- lib/cache/api.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/daemon/lua/sandbox.lua b/daemon/lua/sandbox.lua index 33559dce0..e959df357 100644 --- a/daemon/lua/sandbox.lua +++ b/daemon/lua/sandbox.lua @@ -173,7 +173,7 @@ cache.clear = function (name, exact_name, rr_type, maxcount, callback) if maxcount or callback then error('cache.clear(): maxcount and callback parameters not supported with rr_type') end local ret = ffi.C.kr_cache_remove(kres.context().cache, dname, rr_type) - if ret ~= 0 then error(ffi.string(ffi.C.knot_strerror(ret))) end + if ret < 0 then error(ffi.string(ffi.C.knot_strerror(ret))) end return true end if maxcount == nil then maxcount = 100 end diff --git a/lib/cache/api.c b/lib/cache/api.c index 34b415508..eae62d401 100644 --- a/lib/cache/api.c +++ b/lib/cache/api.c @@ -775,7 +775,13 @@ int kr_cache_remove(struct kr_cache *cache, const knot_dname_t *name, uint16_t t if (ret) return kr_error(ret); knot_db_val_t key = key_exact_type(k, type); - return cache_op(cache, remove, &key, 1); + ret = cache_op(cache, remove, &key, 1); + switch (ret) { + case 0: return 1; + case -ABS(ENOENT): return 0; + default: return ret; + } + } int kr_cache_match(struct kr_cache *cache, const knot_dname_t *name, diff --git a/lib/cache/api.h b/lib/cache/api.h index 6808d4f20..72751ce38 100644 --- a/lib/cache/api.h +++ b/lib/cache/api.h @@ -142,7 +142,7 @@ int kr_cache_materialize(knot_rdataset_t *dst, const struct kr_cache_p *ref, * @param cache cache structure * @param name dname * @param type rr type - * @return 0 or an errcode + * @return number of deleted records, or negative error code * @note only "exact hits" are considered ATM, and * some other information may be removed alongside. */ -- 2.47.2