liminix

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

commit e9370358aedb76d43dcd617eb20005f67357b673
parent 762ce7b6b8ce13eb418d6922b09f999d8dfd01bc
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 21 Apr 2024 11:19:06 +0100

implement "remove" events

Diffstat:
Mpkgs/devout/devout.fnl | 7++++++-
Mpkgs/devout/test.fnl | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/pkgs/devout/devout.fnl b/pkgs/devout/devout.fnl @@ -26,7 +26,12 @@ :find (fn [_ terms] (find-in-database db terms)) :add (fn [_ event-string] (let [e (parse-uevent event-string)] - (tset db e.path e))) + (match e.action + :add (tset db e.path e) + :change (tset db e.path e) + ; ;bind ? + :remove (tset db e.path nil) + ))) :at-path (fn [_ path] (. db path)) })) diff --git a/pkgs/devout/test.fnl b/pkgs/devout/test.fnl @@ -27,6 +27,31 @@ DEVTYPE=disk DISKSEQ=2 SEQNUM=1527") +(local sdb1-insert + "add@/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1\0ACTION=add +DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1 +SUBSYSTEM=block +DEVNAME=/dev/sdb1 +DEVTYPE=partition +DISKSEQ=33 +PARTN=1 +SEQNUM=82381 +MAJOR=8 +MINOR=17") + +(local sdb1-remove + "remove@/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1\0ACTION=remove +DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1 +SUBSYSTEM=block +DEVNAME=/dev/sdb1 +DEVTYPE=partition +DISKSEQ=33 +PARTN=1 +SEQNUM=82386 +MAJOR=8 +MINOR=17") + + (example "when I add a device, I can find it" (let [db (database)] @@ -51,6 +76,21 @@ SEQNUM=1527") (expect= m.major "8")))) (example + "when I add and then remove a device, I cannot retrieve it by path" + (let [db (database)] + (db:add sdb1-insert) + (db:add sdb1-remove) + (expect= (db:at-path "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1") nil))) + +(example + "when I add and then remove a device, I cannot find it" + (let [db (database)] + (db:add sdb1-insert) + (db:add sda-uevent) + (db:add sdb1-remove) + (expect= (db:find {:devname "/dev/sdb1"}) []))) + +(example "when I search on multiple terms it uses all of them" (let [db (database)] (db:add sda-uevent)