]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache.clear: allow callback to modify return value
authorPetr Špaček <petr.spacek@nic.cz>
Thu, 16 Aug 2018 14:50:18 +0000 (16:50 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 17 Aug 2018 13:58:49 +0000 (15:58 +0200)
This is handy mainly for tests but it costs nothing so why not to do it.

daemon/lua/sandbox.lua

index 732d1d50da2872dbc4262aa63813a97d89087d84..9912eee1147bffb88446d54028378930e7efe0a2 100644 (file)
@@ -216,14 +216,15 @@ cache.clear = function (name, exact_name, rr_type, chunk_size, callback)
        if callback == nil then callback =
                function (cberrors, cbname, cbexact_name, cbrr_type, cbchunk_size, cbself)
                        if errors.count < 0 then error(ffi.string(ffi.C.knot_strerror(errors.count))) end
-                       if (errors.count ~= cbchunk_size) then return end
-                       event.after(1, function ()
-                                       cache.clear(cbname, cbexact_name, cbrr_type, cbchunk_size, cbself)
-                               end)
+                       if (errors.count == cbchunk_size) then
+                               event.after(1, function ()
+                                               cache.clear(cbname, cbexact_name, cbrr_type, cbchunk_size, cbself)
+                                       end)
+                       end
+                       return cberrors
                end
        end
-       callback(errors, name, exact_name, rr_type, chunk_size, callback)
-       return errors
+       return callback(errors, name, exact_name, rr_type, chunk_size, callback)
 end
 -- Syntactic sugar for cache
 -- `cache[x] -> cache.get(x)`