liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

json-to-fstree.fnl (915B)


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