From 6fdeedd4abd2ca86811dcd7daa1d73c3145341a7 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 1 Aug 2017 11:12:23 -0400 Subject: [PATCH] Introduce a helper to re-join split absolute paths regardless of platform --- src/native-watcher-registry.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/native-watcher-registry.js b/src/native-watcher-registry.js index 77da22669..fa880b452 100644 --- a/src/native-watcher-registry.js +++ b/src/native-watcher-registry.js @@ -2,6 +2,12 @@ import path from 'path' +// Private: re-join the segments split from an absolute path to form another absolute path. +function absolute(...parts) { + const candidate = path.join(...parts) + return path.isAbsolute(candidate) ? candidate : path.join(path.sep, candidate) +} + // Private: Map userland filesystem watcher subscriptions efficiently to deliver filesystem change notifications to // each watcher with the most efficient coverage of native watchers. // @@ -10,7 +16,7 @@ import path from 'path' // watcher is removed, it will be split into child watchers. // * If any child directories already being watched, stop and replace them with a watcher on the parent directory. // -// Uses a Trie whose structure mirrors the directory structure. +// Uses a trie whose structure mirrors the directory structure. class RegistryTree { // Private: Construct a tree with no native watchers. @@ -33,7 +39,7 @@ class RegistryTree { // * `attachToNative` {Function} invoked with the appropriate native watcher and the absolute path to its watch root. add (pathSegments, attachToNative) { const absolutePathSegments = this.basePathSegments.concat(pathSegments) - const absolutePath = path.join(...absolutePathSegments) + const absolutePath = absolute(...absolutePathSegments) const attachToNew = (childPaths) => { const native = this.createNative(absolutePath) @@ -55,7 +61,7 @@ class RegistryTree { // Attach this Watcher to it as a filtering watcher and record it as a dependent child path. const native = parent.getNativeWatcher() parent.addChildPath(remaining) - attachToNative(native, path.join(...parent.getAbsolutePathSegments())) + attachToNative(native, absolute(...parent.getAbsolutePathSegments())) }, children: children => { // One or more NativeWatchers exist on child directories of the requested path. Create a new native watcher