diff options
| author | Michael Albinus | 2015-09-22 08:40:08 +0200 |
|---|---|---|
| committer | Michael Albinus | 2015-09-22 08:40:08 +0200 |
| commit | 170ed29b438ed0d9f31f1cd1f2f6d9808540763d (patch) | |
| tree | dd93c9b19aff65f669db27c11318a98d1a3aecd4 /src | |
| parent | 27f871907cc24f33a7d12ac3a4ab71a88f0bc554 (diff) | |
| download | emacs-170ed29b438ed0d9f31f1cd1f2f6d9808540763d.tar.gz emacs-170ed29b438ed0d9f31f1cd1f2f6d9808540763d.zip | |
Implement gfile-valid-p
* lisp/filenotify.el (file-notify-callback): Fix typo.
(gfile-valid-p): Remove defalias.
* src/gfilenotify.c (dir_monitor_callback): Cancel the monitor if
the file or directory to be watched is deleted.
(Fgfile_add_watch): Make watch_object a triple.
(Fgfile_rm_watch): Check, whether watch is cancelled already.
(Fgfile_valid_p): New defun.
(syms_of_gfilenotify): Declare Sgfile_valid_p.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gfilenotify.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 5c6ebe65d87..1439666f5f8 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c | |||
| @@ -29,6 +29,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 29 | #include "process.h" | 29 | #include "process.h" |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | /* This is a list, elements are triples (DESCRIPTOR FILE CALLBACK) */ | ||
| 32 | static Lisp_Object watch_list; | 33 | static Lisp_Object watch_list; |
| 33 | 34 | ||
| 34 | /* This is the callback function for arriving signals from | 35 | /* This is the callback function for arriving signals from |
| @@ -93,10 +94,17 @@ dir_monitor_callback (GFileMonitor *monitor, | |||
| 93 | Fcons (symbol, | 94 | Fcons (symbol, |
| 94 | Fcons (build_string (name), | 95 | Fcons (build_string (name), |
| 95 | otail))), | 96 | otail))), |
| 96 | XCDR (watch_object)); | 97 | XCAR (XCDR (XCDR (watch_object)))); |
| 97 | 98 | ||
| 98 | /* Store it into the input event queue. */ | 99 | /* Store it into the input event queue. */ |
| 99 | kbd_buffer_store_event (&event); | 100 | kbd_buffer_store_event (&event); |
| 101 | |||
| 102 | /* Cancel monitor if file or directory is deleted. */ | ||
| 103 | if (((event_type == G_FILE_MONITOR_EVENT_DELETED) || | ||
| 104 | (event_type == G_FILE_MONITOR_EVENT_MOVED)) && | ||
| 105 | (strcmp (name, SSDATA (XCAR (XCDR (watch_object)))) == 0) && | ||
| 106 | (!g_file_monitor_is_cancelled (monitor))) | ||
| 107 | g_file_monitor_cancel (monitor); | ||
| 100 | } | 108 | } |
| 101 | 109 | ||
| 102 | /* Cleanup. */ | 110 | /* Cleanup. */ |
| @@ -198,13 +206,13 @@ will be reported only in case of the `moved' event. */) | |||
| 198 | (GCallback) dir_monitor_callback, NULL); | 206 | (GCallback) dir_monitor_callback, NULL); |
| 199 | 207 | ||
| 200 | /* Store watch object in watch list. */ | 208 | /* Store watch object in watch list. */ |
| 201 | watch_object = Fcons (watch_descriptor, callback); | 209 | watch_object = list3 (watch_descriptor, file, callback); |
| 202 | watch_list = Fcons (watch_object, watch_list); | 210 | watch_list = Fcons (watch_object, watch_list); |
| 203 | 211 | ||
| 204 | return watch_descriptor; | 212 | return watch_descriptor; |
| 205 | } | 213 | } |
| 206 | 214 | ||
| 207 | DEFUN ("gfile-rm-watch", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0, | 215 | DEFUN ("gfile-rm-watc", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0, |
| 208 | doc: /* Remove an existing WATCH-DESCRIPTOR. | 216 | doc: /* Remove an existing WATCH-DESCRIPTOR. |
| 209 | 217 | ||
| 210 | WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) | 218 | WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) |
| @@ -218,11 +226,12 @@ WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) | |||
| 218 | 226 | ||
| 219 | eassert (INTEGERP (watch_descriptor)); | 227 | eassert (INTEGERP (watch_descriptor)); |
| 220 | GFileMonitor *monitor = XINTPTR (watch_descriptor); | 228 | GFileMonitor *monitor = XINTPTR (watch_descriptor); |
| 221 | if (!g_file_monitor_cancel (monitor)) | 229 | if (!g_file_monitor_is_cancelled (monitor) && |
| 222 | xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"), | 230 | !g_file_monitor_cancel (monitor)) |
| 223 | watch_descriptor); | 231 | xsignal2 (Qfile_notify_error, build_string ("Could not rm watch"), |
| 232 | watch_descriptor); | ||
| 224 | 233 | ||
| 225 | /* Remove watch descriptor from watch list. */ | 234 | /* Remove watch descriptor from watch list. */ |
| 226 | watch_list = Fdelq (watch_object, watch_list); | 235 | watch_list = Fdelq (watch_object, watch_list); |
| 227 | 236 | ||
| 228 | /* Cleanup. */ | 237 | /* Cleanup. */ |
| @@ -231,6 +240,27 @@ WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) | |||
| 231 | return Qt; | 240 | return Qt; |
| 232 | } | 241 | } |
| 233 | 242 | ||
| 243 | DEFUN ("gfile-valid-p", Fgfile_valid_p, Sgfile_valid_p, 1, 1, 0, | ||
| 244 | doc: /* "Check a watch specified by its WATCH-DESCRIPTOR. | ||
| 245 | |||
| 246 | WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. | ||
| 247 | |||
| 248 | A watch can become invalid if the file or directory it watches is | ||
| 249 | deleted, or if the watcher thread exits abnormally for any other | ||
| 250 | reason. Removing the watch by calling `gfile-rm-watch' also makes it | ||
| 251 | invalid. */) | ||
| 252 | (Lisp_Object watch_descriptor) | ||
| 253 | { | ||
| 254 | Lisp_Object watch_object = Fassoc (watch_descriptor, watch_list); | ||
| 255 | if (NILP (watch_object)) | ||
| 256 | return Qnil; | ||
| 257 | else | ||
| 258 | { | ||
| 259 | GFileMonitor *monitor = XINTPTR (watch_descriptor); | ||
| 260 | return g_file_monitor_is_cancelled (monitor) ? Qnil : Qt; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 234 | 264 | ||
| 235 | void | 265 | void |
| 236 | globals_of_gfilenotify (void) | 266 | globals_of_gfilenotify (void) |
| @@ -246,6 +276,7 @@ syms_of_gfilenotify (void) | |||
| 246 | { | 276 | { |
| 247 | defsubr (&Sgfile_add_watch); | 277 | defsubr (&Sgfile_add_watch); |
| 248 | defsubr (&Sgfile_rm_watch); | 278 | defsubr (&Sgfile_rm_watch); |
| 279 | defsubr (&Sgfile_valid_p); | ||
| 249 | 280 | ||
| 250 | /* Filter objects. */ | 281 | /* Filter objects. */ |
| 251 | DEFSYM (Qwatch_mounts, "watch-mounts"); /* G_FILE_MONITOR_WATCH_MOUNTS */ | 282 | DEFSYM (Qwatch_mounts, "watch-mounts"); /* G_FILE_MONITOR_WATCH_MOUNTS */ |