From: Vladimír Čunát Date: Wed, 15 Aug 2018 15:31:29 +0000 (+0200) Subject: cache API: avoid some ENOENT errors X-Git-Tag: v3.0.0~1^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e3779be4c0fabaadd6b37c525278b6a6c99593a;p=thirdparty%2Fknot-resolver.git cache API: avoid some ENOENT errors --- 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. */