From bf5038df4008d894409dac4d6e64a94f5630bf61 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 21 Nov 2013 14:19:42 +0400 Subject: [PATCH] fsevents: fix subfolder check First of all, a bit of explanation of what happens there: 1. FSEvents emits absolute paths to changed files or directories 2. We cut off the first part of such paths, which is equal to handle's real path ('/dir/subdir/subsubdir`, without trailing slash) 3. Then, if we are running in non-recursive mode, we discard paths that have slashes ('/') as a non-first character in them --- src/unix/fsevents.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index 3618f469..20c7ae05 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -251,13 +251,15 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, if (strncmp(path, handle->realpath, handle->realpath_len) != 0) continue; - path += handle->realpath_len; - len -= handle->realpath_len; + if (handle->realpath_len > 1 || *handle->realpath != '/') { + path += handle->realpath_len; + len -= handle->realpath_len; - /* Skip back slash */ - if (*path != 0) { - path++; - len--; + /* Skip forward slash */ + if (*path != '\0') { + path++; + len--; + } } #ifdef MAC_OS_X_VERSION_10_7 @@ -267,9 +269,9 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, #endif /* MAC_OS_X_VERSION_10_7 */ /* Do not emit events from subdirectories (without option set) */ - if ((handle->cf_flags & UV_FS_EVENT_RECURSIVE) == 0) { - pos = strchr(path, '/'); - if (pos != NULL && pos != path + 1) + if ((handle->cf_flags & UV_FS_EVENT_RECURSIVE) == 0 && *path != 0) { + pos = strchr(path + 1, '/'); + if (pos != NULL) continue; }