]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
prefill: remove depedency on lua-filesystem (lfs)
authorLukáš Ježek <lukas.jezek@nic.cz>
Wed, 18 Dec 2019 14:13:56 +0000 (15:13 +0100)
committerLukáš Ježek <lukas.jezek@nic.cz>
Wed, 18 Dec 2019 14:16:14 +0000 (15:16 +0100)
daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
daemon/packaging/debian/10/rundeps
distro/arch/PKGBUILD
distro/deb/control
distro/rpm/knot-resolver.spec
lib/utils.c
lib/utils.h
modules/prefill/README.rst
modules/prefill/prefill.lua

index c68ece028c3ac0b308c8d958de593d7c2afd0a41..3afd239e03bcc8dbe5a4bbe6da01100861a64896 100644 (file)
@@ -361,6 +361,7 @@ _Bool kr_zonecut_is_empty(struct kr_zonecut *);
 void kr_zonecut_set(struct kr_zonecut *, const knot_dname_t *);
 uint64_t kr_now();
 const char *kr_strptime_diff(const char *, const char *, const char *, double *);
+time_t kr_file_mtime(const char *);
 void lru_free_items_impl(struct lru *);
 struct lru *lru_create_impl(unsigned int, unsigned int, knot_mm_t *, knot_mm_t *);
 void *lru_get_impl(struct lru *, const char *, unsigned int, unsigned int, _Bool, _Bool *);
index f6f3555636fee9dbf3a968d8cac136f4e31c3e0e..3ebe177e8c02ca4b11ebfd68481a43270167bd55 100755 (executable)
@@ -224,6 +224,7 @@ ${CDEFS} ${LIBKRES} functions <<-EOF
        kr_zonecut_set
        kr_now
        kr_strptime_diff
+       kr_file_mtime
        lru_free_items_impl
        lru_create_impl
        lru_get_impl
index fc5b8d00fee17ee462eb9f1f95171508833944c6..df3df44b96d455369875b5ef694a0690c5763e26 100644 (file)
@@ -2,7 +2,6 @@ adduser
 dns-root-data
 lua-sec
 lua-socket
-lua-filesystem
 systemd
 libc6
 libdnssec7
index e202d7143e8ab4bc4b0ddb65d8cda2296c85628d..a943703609a0ca61ac548b040e28c04cd88d8af1 100644 (file)
@@ -28,7 +28,6 @@ optdepends=(
     'lua51-basexx: experimental_dot_auth module',
     'lua51-cqueues: http and dns64 module, policy.rpz() function',
     'lua51-http: http module',
-    'lua51-filesystem: prefill module',
     'lua51-psl: policy.slice_randomize_psl() function',
 )
 makedepends=(
index 957bfe755d2067be010445e5b9ca84ab5061c569..9f519962ed502e648e702b938d0649bc44cf7d52 100644 (file)
@@ -32,7 +32,6 @@ Depends:
  dns-root-data,
  lua-sec,
  lua-socket,
- lua-filesystem,
  systemd,
  ${misc:Depends},
  ${shlibs:Depends},
index f6cf0841870633e2ec97754a325320ca2728dc47..c22b1f672306da6f68cabaa138b3cc31649828c8 100644 (file)
@@ -58,7 +58,6 @@ Requires:       lua-basexx
 Requires:       lua-psl
 Requires:       lua-socket
 Requires:       lua-sec
-Requires:       lua-filesystem
 Requires(pre):  shadow-utils
 %endif
 %if 0%{?fedora}
@@ -67,7 +66,6 @@ BuildRequires:  python3-sphinx
 Requires:       lua5.1-basexx
 Requires:       lua5.1-cqueues
 Recommends:     lua5.1-psl
-Requires:       lua-filesystem-compat
 Requires:       lua-socket-compat
 Requires:       lua-sec-compat
 Requires(pre):  shadow-utils
@@ -82,7 +80,6 @@ BuildRequires:  openssl-devel
 %define NINJA ninja
 BuildRequires:  lmdb-devel
 BuildRequires:  python3-Sphinx
-Requires:       lua51-luafilesystem
 Requires:       lua51-luasocket
 Requires:       lua51-luasec
 Requires(pre):  shadow
index 140e8ecb33017386d7346fbe3cc2e7c9a482d35e..0bb36484c2a999b18c72f65b534053ab1cb1b52a 100644 (file)
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 #include <sys/un.h>
 
 /* Always compile-in log symbols, even if disabled. */
@@ -1235,3 +1236,13 @@ uint16_t kr_rrsig_type_covered(const knot_rdata_t *rdata)
        return knot_rrsig_type_covered(rdata);
 }
 
+time_t kr_file_mtime (const char* fname) {
+       struct stat fstat;
+
+       if (stat(fname, &fstat) != 0) {
+               return 0;
+       }
+
+       return fstat.st_mtime;
+}
+
index 0c932bae30293dbe19d30e7d8bcd60dcb8409b89..44e4e226446c2641dd47ac7f887e72ddf995e8a6 100644 (file)
@@ -541,3 +541,4 @@ KR_EXPORT uint16_t kr_pkt_qtype(const knot_pkt_t *pkt);
 KR_EXPORT uint32_t kr_rrsig_sig_inception(const knot_rdata_t *rdata);
 KR_EXPORT uint32_t kr_rrsig_sig_expiration(const knot_rdata_t *rdata);
 KR_EXPORT uint16_t kr_rrsig_type_covered(const knot_rdata_t *rdata);
+KR_EXPORT time_t kr_file_mtime (const char* fname);
index b9754091a63a36d163feb713b669b18e135fc07d..024dc06d0b8d42dfb9777c860ed9f23afc294502 100644 (file)
@@ -36,7 +36,6 @@ Only root zone import is supported at the moment.
 Dependencies
 ^^^^^^^^^^^^
 
-Depends on the luasec_ and luafilesystem_ libraries.
+Depends on the luasec_ library.
 
 .. _luasec: https://luarocks.org/modules/brunoos/luasec
-.. _luafilesystem: https://keplerproject.github.io/luafilesystem/
index 1f99d2d1062aa8d2078e19952ef104a9a35f6226..38fea105104c6e58075aa6acf7ab21c08cc1e87e 100644 (file)
@@ -1,6 +1,6 @@
 local https = require('ssl.https')
 local ltn12 = require('ltn12')
-local lfs = require('lfs')
+local ffi = require('ffi')
 
 local rz_url = "https://www.internic.net/domain/root.zone"
 local rz_local_fname = "root.zone"
@@ -70,9 +70,12 @@ end
 -- returns: number of seconds the file is valid for
 -- 0 indicates immediate download
 local function get_file_ttl(fname)
-       local attrs = lfs.attributes(fname)
-       if attrs then
-               local age = os.time() - attrs.modification
+       local c_str = ffi.new("char[?]", #fname)
+       ffi.copy(c_str, fname)
+       local mtime = tonumber(ffi.C.kr_file_mtime(c_str))
+
+       if mtime > 0 then
+               local age = os.time() - mtime
                return math.max(
                        rz_cur_interval - age,
                        0)