Prefix all non-standard eggs
This commit is contained in:
parent
85b85253f4
commit
f4b47d3756
64
chatdir.scm
64
chatdir.scm
|
@ -15,14 +15,11 @@
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken file) (chicken file posix) (chicken io) (chicken keyword) (chicken random)
|
(chicken file) (chicken file posix) (chicken pathname) (chicken io)
|
||||||
(chicken pathname)
|
(chicken random) (chicken string)
|
||||||
(chicken pretty-print) (chicken process-context)
|
srfi-1 srfi-13 srfi-19
|
||||||
(chicken process-context posix) (chicken string)
|
(prefix inotify inotify:)
|
||||||
srfi-1 srfi-13 srfi-18 srfi-19 srfi-69 srfi-180
|
(prefix xattr xattr:))
|
||||||
inotify
|
|
||||||
xattr
|
|
||||||
getopt-long)
|
|
||||||
|
|
||||||
|
|
||||||
;; Wrapper around `directory` that lists a dir's files as a relative path
|
;; Wrapper around `directory` that lists a dir's files as a relative path
|
||||||
|
@ -37,9 +34,9 @@
|
||||||
(define (path->wd path)
|
(define (path->wd path)
|
||||||
(car
|
(car
|
||||||
(filter (lambda (wd)
|
(filter (lambda (wd)
|
||||||
(string=? (normalize-pathname (wd->path wd))
|
(string=? (normalize-pathname (inotify:wd->path wd))
|
||||||
(normalize-pathname path)))
|
(normalize-pathname path)))
|
||||||
(wd-list))))
|
(inotify:wd-list))))
|
||||||
|
|
||||||
|
|
||||||
;; Attempt to remove an inotify watch; if it's already been removed, no sweat
|
;; Attempt to remove an inotify watch; if it's already been removed, no sweat
|
||||||
|
@ -47,7 +44,7 @@
|
||||||
(define (attempt-remove-watch! watch)
|
(define (attempt-remove-watch! watch)
|
||||||
(handle-exceptions exn
|
(handle-exceptions exn
|
||||||
#t
|
#t
|
||||||
(remove-watch! watch)))
|
(inotify:remove-watch! watch)))
|
||||||
|
|
||||||
|
|
||||||
;; Tidies up a channel directory: Removes `online` and `offline` user links.
|
;; Tidies up a channel directory: Removes `online` and `offline` user links.
|
||||||
|
@ -238,7 +235,7 @@
|
||||||
|
|
||||||
;; Write the xattrs (if applicable)
|
;; Write the xattrs (if applicable)
|
||||||
(map (lambda (xattr-cons)
|
(map (lambda (xattr-cons)
|
||||||
(set-xattr path (symbol->string (car xattr-cons))
|
(xattr:set-xattr path (symbol->string (car xattr-cons))
|
||||||
(cdr xattr-cons)))
|
(cdr xattr-cons)))
|
||||||
xattr-alist)))
|
xattr-alist)))
|
||||||
|
|
||||||
|
@ -253,8 +250,8 @@
|
||||||
(cons (directory-file-get directory key)
|
(cons (directory-file-get directory key)
|
||||||
(map (lambda (xattr)
|
(map (lambda (xattr)
|
||||||
(cons (string->symbol xattr)
|
(cons (string->symbol xattr)
|
||||||
(get-xattr path xattr)))
|
(xattr:get-xattr path xattr)))
|
||||||
(list-xattrs path)))))
|
(xattr:list-xattrs path)))))
|
||||||
|
|
||||||
|
|
||||||
;; Sets a channel's metadata value; that is, sets the contents of the file
|
;; Sets a channel's metadata value; that is, sets the contents of the file
|
||||||
|
@ -343,7 +340,7 @@
|
||||||
(define (channel-messages-by-xattr root channel xattr value)
|
(define (channel-messages-by-xattr root channel xattr value)
|
||||||
(filter
|
(filter
|
||||||
(lambda (message-leaf)
|
(lambda (message-leaf)
|
||||||
(string=? (get-xattr (subpath root channel message-leaf)
|
(string=? (xattr:get-xattr (subpath root channel message-leaf)
|
||||||
xattr)
|
xattr)
|
||||||
value))
|
value))
|
||||||
(channel-messages root channel)))
|
(channel-messages root channel)))
|
||||||
|
@ -372,7 +369,7 @@
|
||||||
(filter
|
(filter
|
||||||
(lambda (message-leaf)
|
(lambda (message-leaf)
|
||||||
(let* ([message-path (subpath root channel message-leaf)]
|
(let* ([message-path (subpath root channel message-leaf)]
|
||||||
[message-date (string->date (get-xattr message-path "user.chat.date")
|
[message-date (string->date (xattr:get-xattr message-path "user.chat.date")
|
||||||
"~Y-~m-~dT~H:~M:~S~z")])
|
"~Y-~m-~dT~H:~M:~S~z")])
|
||||||
(and (date<=? min-date message-date)
|
(and (date<=? min-date message-date)
|
||||||
(date<=? message-date max-date))))
|
(date<=? message-date max-date))))
|
||||||
|
@ -382,10 +379,10 @@
|
||||||
;; Initialization for the input loop
|
;; Initialization for the input loop
|
||||||
(define (input-loop-init root-dir callbacks-alist)
|
(define (input-loop-init root-dir callbacks-alist)
|
||||||
(let ([join-callback (alist-ref 'join-channel callbacks-alist)])
|
(let ([join-callback (alist-ref 'join-channel callbacks-alist)])
|
||||||
(init!)
|
(inotify:init!)
|
||||||
;; Start watching the chatdir (for new channel joins, etc)
|
;; Start watching the chatdir (for new channel joins, etc)
|
||||||
(add-watch! root-dir
|
(inotify:add-watch!
|
||||||
'(onlydir moved-to moved-from delete delete-self create))
|
root-dir '(onlydir moved-to moved-from delete delete-self create))
|
||||||
|
|
||||||
;; Auto-join channels with all pre-existing channel directories
|
;; Auto-join channels with all pre-existing channel directories
|
||||||
(map (lambda (path)
|
(map (lambda (path)
|
||||||
|
@ -394,7 +391,7 @@
|
||||||
(if join-callback
|
(if join-callback
|
||||||
(apply join-callback (list channel-dirname)))
|
(apply join-callback (list channel-dirname)))
|
||||||
|
|
||||||
(add-watch! in-path '(moved-to close-write))
|
(inotify:add-watch! in-path '(moved-to close-write))
|
||||||
(print "Joined and watching: " in-path)))
|
(print "Joined and watching: " in-path)))
|
||||||
(filter directory-exists? (directory-rel irc-dir)))))
|
(filter directory-exists? (directory-rel irc-dir)))))
|
||||||
|
|
||||||
|
@ -402,7 +399,7 @@
|
||||||
;; Handles all inotify-watched file events from the top-level IRC-directory.
|
;; Handles all inotify-watched file events from the top-level IRC-directory.
|
||||||
;; Mainly, checking for newly-joined or left channels.
|
;; Mainly, checking for newly-joined or left channels.
|
||||||
(define (handle-main-dir-event callbacks-alist event)
|
(define (handle-main-dir-event callbacks-alist event)
|
||||||
(let ([flags (event-flags event)]
|
(let ([flags (inotify:event-flags event)]
|
||||||
[leave-callback (alist-ref 'leave-channel callbacks-alist)]
|
[leave-callback (alist-ref 'leave-channel callbacks-alist)]
|
||||||
[join-callback (alist-ref 'join-channel callbacks-alist)])
|
[join-callback (alist-ref 'join-channel callbacks-alist)])
|
||||||
(cond
|
(cond
|
||||||
|
@ -411,8 +408,11 @@
|
||||||
[(or (member 'moved-from flags)
|
[(or (member 'moved-from flags)
|
||||||
(member 'delete flags)
|
(member 'delete flags)
|
||||||
(member 'delete-self flags))
|
(member 'delete-self flags))
|
||||||
(let* ([channel (event-name event)]
|
(let* ([channel (inotify:event-name event)]
|
||||||
[channel-inpath (string-append (wd->path (event-wd event)) channel "/.in")]
|
[channel-inpath
|
||||||
|
(string-append (inotify:wd->path
|
||||||
|
(inotify:event-wd event))
|
||||||
|
channel "/.in")]
|
||||||
[channel-wd (path->wd channel-inpath)])
|
[channel-wd (path->wd channel-inpath)])
|
||||||
(print "Remove watch for " channel-inpath "…")
|
(print "Remove watch for " channel-inpath "…")
|
||||||
(if (and channel-wd (member channel-wd (wd-list)))
|
(if (and channel-wd (member channel-wd (wd-list)))
|
||||||
|
@ -423,7 +423,7 @@
|
||||||
;; If a dir's been created for a channel, maybe-join, then watch input!
|
;; If a dir's been created for a channel, maybe-join, then watch input!
|
||||||
[(or (member 'create flags)
|
[(or (member 'create flags)
|
||||||
(member 'moved-to flags))
|
(member 'moved-to flags))
|
||||||
(let* ([channel (event->pathname event)])
|
(let* ([channel (inotify:event->pathname event)])
|
||||||
(print "Attempting to join channel " dirname "…")
|
(print "Attempting to join channel " dirname "…")
|
||||||
(if join-callback
|
(if join-callback
|
||||||
(apply join-callback (list path))))])))
|
(apply join-callback (list path))))])))
|
||||||
|
@ -431,16 +431,16 @@
|
||||||
|
|
||||||
(define (channel-joined root-dir channel)
|
(define (channel-joined root-dir channel)
|
||||||
(let* ([in-path (normalize-pathname (string-append root-dir "/" channel "/.in"))])
|
(let* ([in-path (normalize-pathname (string-append root-dir "/" channel "/.in"))])
|
||||||
(add-watch! in-path '(moved-to close-write))
|
(inotify:add-watch! in-path '(moved-to close-write))
|
||||||
(print "Began watching input " in-path ".")))
|
(print "Began watching input " in-path ".")))
|
||||||
|
|
||||||
|
|
||||||
;; Handles an inotify event that pertains to a channel's .in/ directory
|
;; Handles an inotify event that pertains to a channel's .in/ directory
|
||||||
(define (handle-channel-dir-event callbacks-alist event)
|
(define (handle-channel-dir-event callbacks-alist event)
|
||||||
(let* ([event-dir (pathname-directory (event->pathname event))]
|
(let* ([event-dir (pathname-directory (inotify:event->pathname event))]
|
||||||
[dirname (pathname-file event-dir)]
|
[dirname (pathname-file event-dir)]
|
||||||
[channel (pathname-file (pathname-directory event-dir))]
|
[channel (pathname-file (pathname-directory event-dir))]
|
||||||
[send-message-callback (alist-ref 'send-message callbacks-alsit)])
|
[send-message-callback (alist-ref 'send-message callbacks-alist)])
|
||||||
(cond
|
(cond
|
||||||
;; If input is given to an `.in` dir… well, send that darn message!
|
;; If input is given to an `.in` dir… well, send that darn message!
|
||||||
;; What're you wating for?
|
;; What're you wating for?
|
||||||
|
@ -448,16 +448,16 @@
|
||||||
send-message-callback)
|
send-message-callback)
|
||||||
(map (lambda (message)
|
(map (lambda (message)
|
||||||
(apply send-message (list channel message)))
|
(apply send-message (list channel message)))
|
||||||
(with-input-from-file (event->pathname event)
|
(with-input-from-file (inotify:event->pathname event)
|
||||||
read-lines))
|
read-lines))
|
||||||
(delete-file* (event->pathname event))])))
|
(delete-file* (inotify:event->pathname event))])))
|
||||||
|
|
||||||
|
|
||||||
;; Handle a single inotify file event, as part of the input loop
|
;; Handle a single inotify file event, as part of the input loop
|
||||||
(define (handle-file-event root-dir callbacks-alist event)
|
(define (handle-file-event root-dir callbacks-alist event)
|
||||||
(if (not (member 'ignored (event-flags event)))
|
(if (not (member 'ignored (event-flags event)))
|
||||||
(let* ([flags (event-flags event)]
|
(let* ([flags (inotify:event-flags event)]
|
||||||
[wd-path (wd->path (event-wd event))]
|
[wd-path (inotify:wd->path (inotify:event-wd event))]
|
||||||
[main-dir? (string=? wd-path root-dir)])
|
[main-dir? (string=? wd-path root-dir)])
|
||||||
(if main-dir?
|
(if main-dir?
|
||||||
(handle-main-dir-event root-dir callbacks-alist event)
|
(handle-main-dir-event root-dir callbacks-alist event)
|
||||||
|
@ -472,7 +472,7 @@
|
||||||
(define (input-loop root-dir callbacks-alist)
|
(define (input-loop root-dir callbacks-alist)
|
||||||
(map (lambda (event)
|
(map (lambda (event)
|
||||||
(handle-file-event root-dir callbacks-alist event))
|
(handle-file-event root-dir callbacks-alist event))
|
||||||
(next-events!))
|
(inotify:next-events!))
|
||||||
|
|
||||||
(input-loop root-dir callbacks-alist))
|
(input-loop root-dir callbacks-alist))
|
||||||
|
|
||||||
|
|
Reference in New Issue