From 74fbe8c7f90cff35d940a6b768087cdcb2ad5083 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Mon, 13 Nov 2017 10:46:58 +0900 Subject: [PATCH 1/2] fixes issue #1 --- src/fs-watcher.lisp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fs-watcher.lisp b/src/fs-watcher.lisp index 0fea568..d830423 100644 --- a/src/fs-watcher.lisp +++ b/src/fs-watcher.lisp @@ -29,8 +29,10 @@ (map nil #'(lambda (pathname) (let ((mtime (mtime pathname))) - (unless (eq mtime - (gethash pathname mtimes)) + (unless (eql mtime + ;; universal time or nil, so = is ng. + ;; eq between integers is impl-dependent behavior + (gethash pathname mtimes)) (funcall callback pathname) (if mtime (setf (gethash pathname mtimes) mtime) From d0646a0473f0ca520cdd38c326021d36fc59b968 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Mon, 13 Nov 2017 10:52:33 +0900 Subject: [PATCH 2/2] modifying the list that it is currently iterating is an undefined behavior. CLHS 3.6 Traversal Rules and Side Effects --- src/fs-watcher.lisp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fs-watcher.lisp b/src/fs-watcher.lisp index d830423..4f7108a 100644 --- a/src/fs-watcher.lisp +++ b/src/fs-watcher.lisp @@ -13,14 +13,14 @@ (run-loop pathnames mtimes callback delay))) (defun dir-contents (pathnames) - "Returns a list of all the contents in a directory" - (mapcar #'(lambda (pathname) - (when (directory-p pathname) - (walk-directory pathname - #'(lambda (pathname) - (push pathname pathnames)) - :directories t))) - pathnames)) + "For each directory, collect the file pathnames recursively. Results are appended and returned as a single list." + (let (acc) + (dolist (pathname pathnames acc) + (if (directory-p pathname) + (walk-directory pathname + #'(lambda (pathname) + (push pathname acc))) + (push pathname acc))))) (defun run-loop (pathnames mtimes callback delay) "The main loop constantly polling the filesystem"