From: Lukáš Ježek Date: Wed, 18 Dec 2019 14:13:56 +0000 (+0100) Subject: prefill: remove depedency on lua-filesystem (lfs) X-Git-Tag: v5.0.0~19^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62a1b1dec82eb054b5b797ac2eae1958f730ef05;p=thirdparty%2Fknot-resolver.git prefill: remove depedency on lua-filesystem (lfs) --- diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index c68ece028..3afd239e0 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -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 *); diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index f6f355563..3ebe177e8 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -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 diff --git a/daemon/packaging/debian/10/rundeps b/daemon/packaging/debian/10/rundeps index fc5b8d00f..df3df44b9 100644 --- a/daemon/packaging/debian/10/rundeps +++ b/daemon/packaging/debian/10/rundeps @@ -2,7 +2,6 @@ adduser dns-root-data lua-sec lua-socket -lua-filesystem systemd libc6 libdnssec7 diff --git a/distro/arch/PKGBUILD b/distro/arch/PKGBUILD index e202d7143..a94370360 100644 --- a/distro/arch/PKGBUILD +++ b/distro/arch/PKGBUILD @@ -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=( diff --git a/distro/deb/control b/distro/deb/control index 957bfe755..9f519962e 100644 --- a/distro/deb/control +++ b/distro/deb/control @@ -32,7 +32,6 @@ Depends: dns-root-data, lua-sec, lua-socket, - lua-filesystem, systemd, ${misc:Depends}, ${shlibs:Depends}, diff --git a/distro/rpm/knot-resolver.spec b/distro/rpm/knot-resolver.spec index f6cf08418..c22b1f672 100644 --- a/distro/rpm/knot-resolver.spec +++ b/distro/rpm/knot-resolver.spec @@ -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 diff --git a/lib/utils.c b/lib/utils.c index 140e8ecb3..0bb36484c 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -40,6 +40,7 @@ #include #include #include +#include #include /* 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; +} + diff --git a/lib/utils.h b/lib/utils.h index 0c932bae3..44e4e2264 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -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); diff --git a/modules/prefill/README.rst b/modules/prefill/README.rst index b9754091a..024dc06d0 100644 --- a/modules/prefill/README.rst +++ b/modules/prefill/README.rst @@ -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/ diff --git a/modules/prefill/prefill.lua b/modules/prefill/prefill.lua index 1f99d2d10..38fea1051 100644 --- a/modules/prefill/prefill.lua +++ b/modules/prefill/prefill.lua @@ -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)