Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/inotify.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ closed with CLOSE-INOTIFY."
being watched by INOTIFY, else NIL. The match is exact."
(cdr (gethash pathname (inotify-pathnames inotify))))

(defun event-pathname/flags (inotify event &optional (handle (slot-value event 'wd)))
(defun event-pathname/flags (inotify event &optional (handle (inotify-event-wd event)))
"Returns two values PATHNAME and FLAGS for an EVENT which were used during
registration. If HANDLE is specified EVENT is ignored."
(let ((list (gethash handle (inotify-handles inotify))))
Expand All @@ -316,14 +316,16 @@ registration. If HANDLE is specified EVENT is ignored."
(check-type flags watch-flag-list)
;; now, :mask-add can't be member of flags
;; merge the flags
(let* ((flags (ensure-list flags))
(rep-flags (if replace-p
(cons :mask-add flags)
flags)))
(let ((it (gethash pathname (inotify-pathnames inotify))))
(if it
(union (third it) rep-flags :test #'eq)
rep-flags))))
;; 20220310 mgr:
;; - if we UNION already we don't need :mask-add
;; - :mask-add is actually just ignored here and not necessary
;; - storing :mask-add in the inotify-pathnames hash is also strange
(let* ((flags (ensure-list flags)))
(if replace-p
flags
(union (third (gethash pathname (inotify-pathnames inotify)))
flags
:test #'eq))))

(defun watch (inotify pathname flags &key (replace-p T))
"Adds PATHNAME (either pathname or string) to be watched and records the
Expand All @@ -332,6 +334,7 @@ inotify(7) for detailed information). Returns a handle which can be used
with UNWATCH and EVENT-PATHNAME/FLAGS. If REPLACE-P is set to T (default),
the flags mask is replaced rather than OR-ed to the current mask (if it
exists). The :MASK-ADD flag is therefore removed from the FLAGS argument."
;; :mask-add is actually nowhere removed (20220310 mgr)
(let* ((flags (sane-user-flags inotify pathname flags :replace-p replace-p))
(handle (watch-raw inotify pathname flags))
(list (list pathname handle flags)))
Expand All @@ -345,7 +348,7 @@ may be one from a given EVENT) or PATHNAME."
(unless (or pathname event handle)
(error "either PATHNAME, EVENT or HANDLE have to be specified"))
(when event
(setf handle (slot-value event 'wd)))
(setf handle (inotify-event-wd event)))
(let ((handle (or handle
(car (pathname-handle/flags inotify pathname))
(error "PATHNAME ~S isn't being watched" pathname)))
Expand Down