]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache API: avoid some ENOENT errors
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 15 Aug 2018 15:31:29 +0000 (17:31 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 17 Aug 2018 13:58:48 +0000 (15:58 +0200)
daemon/lua/sandbox.lua
lib/cache/api.c
lib/cache/api.h

index 33559dce0d2b171430fa2201ab29eadadcb641a6..e959df3578719f442aeeda796f544fc1fd6de77e 100644 (file)
@@ -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
index 34b415508733dc06331a4e26b528753b84885160..eae62d4017d3bbf33496b97464b46799f1c7c364 100644 (file)
@@ -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,
index 6808d4f2090e7c066a7c6cb2f7bb60f12184255f..72751ce3868fa9e46d3c5a4f42470993f930eb2a 100644 (file)
@@ -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.
  */