rename http-fstree => json-to-fstree

it works for file urls as well, not just http
This commit is contained in:
Daniel Barlow
2024-08-28 19:12:00 +01:00
parent da95a9fa62
commit d5d621f310
4 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,37 @@
{
fetchurl,
writeFennel,
fennel,
fennelrepl,
runCommand,
lua,
anoia,
linotify,
lualinux,
fetch-freebsd,
openssl,
rxi-json,
stdenv
}:
let name = "json-to-fstree";
in stdenv.mkDerivation {
inherit name;
src = ./.;
buildInputs = [fetch-freebsd rxi-json openssl lua];
buildPhase = "";
installPhase = ''
mkdir -p $out/bin
cp -p ${writeFennel name {
packages = [
fetch-freebsd
rxi-json
anoia
lualinux
linotify
] ;
mainFunction = "run";
} ./${name}.fnl } $out/bin/${name}
'';
}

View File

@@ -0,0 +1,24 @@
(local json (require :json))
(local http (require :fetch))
(local svc (require :anoia.svc))
(local { : utime } (require :lualinux))
(fn download [url dest]
(match (http.fetch url)
(nil code str)
(assert nil (.. "error " code ": " str))
(body { : last-modified })
(let [service (svc.open dest)
lock (.. dest "/.lock")
state (.. dest "/state")]
(with-open [fout (io.open lock :w)] (fout:write ""))
(service:output "." (json.decode body))
(with-open [fout (io.open state :w)] (fout:write "ok"))
(os.remove lock)
(utime dest last-modified))))
(fn run [] (download (. arg 1) (. arg 2)))
{ : run }