json-to-fstree.fnl (842B)
1 (local json (require :json)) 2 (local http (require :fetch)) 3 (local svc (require :anoia.svc)) 4 (local { : utime } (require :lualinux)) 5 6 (fn download [url dest] 7 (let [state (.. dest "/state") 8 previously (ll.lstat state 12)] 9 (match (http.fetch url "i" previously) 10 (nil 10 _) ; not modified 11 (print (.. url " not modified, already up to date")) 12 13 (nil code str) 14 (assert nil (.. "error " code ": " str)) 15 16 (body { : last-modified }) 17 (let [service (svc.open dest) 18 lock (.. dest "/.lock")] 19 (with-open [fout (io.open lock :w)] (fout:write "")) 20 (service:output "." (json.decode body)) 21 (with-open [fout (io.open state :w)] (fout:write "ok")) 22 (utime state last-modified) 23 (os.remove lock)) 24 25 ))) 26 27 (fn run [] (download (. arg 1) (. arg 2))) 28 29 30 { : run }