2024-04-15 22:15:07 +02:00
|
|
|
(local { : view} (require :fennel))
|
2024-04-20 16:09:50 +02:00
|
|
|
(import-macros { : expect= } :anoia.assert)
|
2024-04-15 22:15:07 +02:00
|
|
|
|
|
|
|
(local subject (require :watch))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Events come from the netlink socket as an initial summary line
|
|
|
|
;; followed by a NUL character followed by newline-separated key=value
|
|
|
|
;; pairs. For ease of editing we don't have NULs in events.txt,
|
|
|
|
;; so we need to massage it into shape here
|
|
|
|
|
|
|
|
(local events
|
|
|
|
(with-open [f (io.open "./events.txt" :r)]
|
|
|
|
(let [text (string.gsub (f:read "*a") "\n\n" "\0") ]
|
|
|
|
(icollect [n (string.gmatch text "([^\0]+)")]
|
|
|
|
(string.gsub n "\n" "\0" 1)))))
|
|
|
|
|
|
|
|
|
|
|
|
(fn next-event []
|
|
|
|
(var i 0)
|
|
|
|
(fn []
|
|
|
|
(let [i_ (+ 1 i)
|
|
|
|
e (. events i_)]
|
|
|
|
(set i i_)
|
|
|
|
e)))
|
|
|
|
|
|
|
|
;; this tests event parsing but not whether anything
|
|
|
|
;; happens as a result of processing them
|
2024-04-20 17:53:43 +02:00
|
|
|
(subject.run-with-fh
|
2024-04-15 22:15:07 +02:00
|
|
|
{ :read (next-event) }
|
2024-04-20 17:53:43 +02:00
|
|
|
["-s" "foo" "-n" (os.getenv "TMPDIR") "partname=backup-disk" ]
|
2024-04-15 22:15:07 +02:00
|
|
|
)
|
2024-04-20 17:53:43 +02:00
|
|
|
|
|
|
|
(print "OK")
|