svc.open accepts a /nix/store folder not an outputs folder
this mostly makes things simpler
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
servicedir:=$(shell mktemp -d)
|
||||
outputdir:=$(servicedir)/.outputs
|
||||
|
||||
default: fs.lua init.lua nl.lua svc.lua process.lua net/constants.lua
|
||||
|
||||
@@ -9,12 +10,13 @@ check:
|
||||
fennel ./run-tests.fnl $(CHECK)
|
||||
fennel test.fnl
|
||||
fennel test-svc.fnl $(servicedir)
|
||||
test -f $(servicedir)/fish
|
||||
test "`cat $(servicedir)/fish`" = "food"
|
||||
test -d $(servicedir)/nested/path
|
||||
test "`cat $(servicedir)/nested/path/name`" = "value"
|
||||
test "`cat $(servicedir)/nested/path/complex/attribute`" = "val"
|
||||
test "`cat $(servicedir)/nested/path/complex/other`" = "42"
|
||||
find $(outputdir) -ls
|
||||
test -f $(outputdir)/fish
|
||||
test "`cat $(outputdir)/fish`" = "food"
|
||||
test -d $(outputdir)/nested/path
|
||||
test "`cat $(outputdir)/nested/path/name`" = "value"
|
||||
test "`cat $(outputdir)/nested/path/complex/attribute`" = "val"
|
||||
test "`cat $(outputdir)/nested/path/complex/other`" = "42"
|
||||
|
||||
|
||||
net/constants.lua: net/constants.c
|
||||
|
1
pkgs/anoia/example-output/.outputs/array/1
Normal file
1
pkgs/anoia/example-output/.outputs/array/1
Normal file
@@ -0,0 +1 @@
|
||||
cat
|
1
pkgs/anoia/example-output/.outputs/array/2
Normal file
1
pkgs/anoia/example-output/.outputs/array/2
Normal file
@@ -0,0 +1 @@
|
||||
dog
|
1
pkgs/anoia/example-output/.outputs/array/3
Normal file
1
pkgs/anoia/example-output/.outputs/array/3
Normal file
@@ -0,0 +1 @@
|
||||
cow
|
1
pkgs/anoia/example-output/.outputs/array/4
Normal file
1
pkgs/anoia/example-output/.outputs/array/4
Normal file
@@ -0,0 +1 @@
|
||||
sheep
|
@@ -1,5 +1,5 @@
|
||||
(local inotify (require :inotify))
|
||||
(local { : file-exists? : dirname } (require :anoia))
|
||||
(local { : file-exists? : dirname : append-path } (require :anoia))
|
||||
(local { : file-type : dir : mktree &as fs } (require :anoia.fs))
|
||||
|
||||
(fn read-line [name]
|
||||
@@ -25,7 +25,7 @@
|
||||
(with-open [f (assert (io.open pathname :w) (.. "can't open " pathname))]
|
||||
(f:write value))
|
||||
"table" (each [k v (pairs value)]
|
||||
(write-value (.. pathname "/" k) v))))
|
||||
(write-value (append-path pathname k) v))))
|
||||
|
||||
(fn read-value [pathname]
|
||||
(case (file-type pathname)
|
||||
@@ -33,7 +33,7 @@
|
||||
:directory
|
||||
(collect [f (fs.dir pathname)]
|
||||
(when (not (or (= f ".") (= f "..")))
|
||||
(values f (read-value ( .. pathname "/" f)))))
|
||||
(values f (read-value (append-path pathname f)))))
|
||||
:file
|
||||
(read-line pathname)
|
||||
:link
|
||||
@@ -50,15 +50,17 @@
|
||||
|
||||
(fn open [directory]
|
||||
(let [watcher (watch-fsevents directory)
|
||||
has-file? (fn [filename] (file-exists? (.. directory "/" filename)))]
|
||||
has-file? #(file-exists? (append-path directory $1))
|
||||
outputs-dir (append-path directory ".outputs")]
|
||||
{
|
||||
:wait #(watcher:read)
|
||||
:ready? (fn [self]
|
||||
(and (has-file? "state") (not (has-file? ".lock"))))
|
||||
(and (has-file? ".outputs/state")
|
||||
(not (has-file? ".outputs/.lock"))))
|
||||
:output (fn [_ filename new-value]
|
||||
(if new-value
|
||||
(write-value (.. directory "/" filename) new-value)
|
||||
(read-value (.. directory "/" filename))))
|
||||
(write-value (append-path outputs-dir filename) new-value)
|
||||
(read-value (append-path outputs-dir filename))))
|
||||
:close #(watcher:close)
|
||||
:fileno #(watcher:fileno)
|
||||
: events
|
||||
|
@@ -28,7 +28,7 @@
|
||||
: ipairs
|
||||
:output
|
||||
(fn [service-path path default]
|
||||
(let [s (assert (svc.open (.. service-path "/.outputs")))]
|
||||
(let [s (assert (svc.open service-path))]
|
||||
(or (s:output path) default)))
|
||||
:lua_quote #(string.format "%q" $1)
|
||||
:json_quote (fn [x] (.. "\"" (json-escape x) "\""))
|
||||
|
@@ -71,7 +71,7 @@
|
||||
|
||||
(fn open-services [output-references]
|
||||
(collect [s p (pairs output-references)]
|
||||
(values (svc.open (.. s "/.outputs")) p)))
|
||||
(values (svc.open s) p)))
|
||||
|
||||
(fn run []
|
||||
(let [trees {}
|
||||
|
@@ -50,8 +50,7 @@
|
||||
|
||||
(fn run []
|
||||
(let [{: out-path : watched-service : path } (parse-args arg)
|
||||
dir (.. watched-service "/.outputs")
|
||||
service (assert (svc.open dir))]
|
||||
service (assert (svc.open watched-service))]
|
||||
(accumulate [tree {}
|
||||
v (service:events)]
|
||||
(write-changes out-path tree (or (service:output path) {})))))
|
||||
|
Reference in New Issue
Block a user