From: Michael Albinus Date: Fri, 2 Feb 2018 17:51:25 +0000 (+0100) Subject: Handle quoted remote file names for file notifications X-Git-Tag: emacs-27.0.90~5746 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=344750aef4a8e8c67b1857cf0fe413ba855026d6;p=emacs.git Handle quoted remote file names for file notifications * lisp/filenotify.el (file-notify-add-watch): Do not suppress other file name handlers when FILE is quoted. * test/lisp/filenotify-tests.el (file-notify-test-remote-temporary-file-directory): Beware quoted `temporary-file-directory'. * test/lisp/files-tests.el (files-tests-file-name-non-special-quote-unquote): Improve test. --- diff --git a/lisp/filenotify.el b/lisp/filenotify.el index 442dc891571..d88578b65c8 100644 --- a/lisp/filenotify.el +++ b/lisp/filenotify.el @@ -307,15 +307,12 @@ FILE is the name of the file whose event is being reported." (unless (functionp callback) (signal 'wrong-type-argument `(,callback))) - (let* ((quoted (file-name-quoted-p file)) - (file (file-name-unquote file)) - (file-name-handler-alist (if quoted nil file-name-handler-alist)) - (handler (find-file-name-handler file 'file-notify-add-watch)) - (dir (directory-file-name - (if (file-directory-p file) - file - (file-name-directory file)))) - desc func l-flags) + (let ((handler (find-file-name-handler file 'file-notify-add-watch)) + (dir (directory-file-name + (if (file-directory-p file) + file + (file-name-directory file)))) + desc func l-flags) (unless (file-directory-p dir) (signal 'file-notify-error `("Directory does not exist" ,dir))) @@ -366,6 +363,10 @@ FILE is the name of the file whose event is being reported." func (if (eq file-notify--library 'kqueue) file dir) l-flags 'file-notify-callback))) + ;; We do not want to enter quoted file names into the hash. + (setq file (file-name-unquote file) + dir (file-name-unquote dir)) + ;; Modify `file-notify-descriptors'. (let ((watch (file-notify--watch-make dir diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index f2feef6132b..219fa746119 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el @@ -57,9 +57,10 @@ 'tramp-default-host-alist `("\\`mock\\'" nil ,(system-name))) ;; Emacs' Makefile sets $HOME to a nonexistent value. Needed in - ;; batch mode only, therefore. + ;; batch mode only, therefore. `temporary-file-directory' might + ;; be quoted, so we unquote it just in case. (unless (and (null noninteractive) (file-directory-p "~/")) - (setenv "HOME" temporary-file-directory)) + (setenv "HOME" (file-name-unquote temporary-file-directory))) (format "/mock::%s" temporary-file-directory))) "Temporary directory for Tramp tests.") diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 6b394cd5b7b..90e5ebf2153 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -268,7 +268,14 @@ be $HOME." (should (file-name-quoted-p (file-name-quote temporary-file-directory))) (should (equal temporary-file-directory (file-name-unquote - (file-name-quote temporary-file-directory)))))) + (file-name-quote temporary-file-directory)))) + ;; It does not hurt to quote/unquote a file several times. + (should (equal (file-name-quote temporary-file-directory) + (file-name-quote + (file-name-quote temporary-file-directory)))) + (should (equal (file-name-unquote temporary-file-directory) + (file-name-unquote + (file-name-unquote temporary-file-directory)))))) (ert-deftest files-tests--file-name-non-special--subprocess () "Check that Bug#25949 is fixed."