diff --git a/src/vs/workbench/services/files/node/watcher/nsfw/nsfwWatcherService.ts b/src/vs/workbench/services/files/node/watcher/nsfw/nsfwWatcherService.ts index b05274d5856eb3c2124612e23596c38418f82037..d3ef72006c88c7d3090f6c755bacdb355f3734b4 100644 --- a/src/vs/workbench/services/files/node/watcher/nsfw/nsfwWatcherService.ts +++ b/src/vs/workbench/services/files/node/watcher/nsfw/nsfwWatcherService.ts @@ -15,6 +15,7 @@ import { ThrottledDelayer } from 'vs/base/common/async'; import { FileChangeType } from 'vs/platform/files/common/files'; import { normalizeNFC } from 'vs/base/common/normalization'; import { Event, Emitter } from 'vs/base/common/event'; +import { realcaseSync, realpathSync } from 'vs/base/node/extfs'; const nsfwActionToRawChangeType: { [key: number]: number } = []; nsfwActionToRawChangeType[nsfw.actions.CREATED] = FileChangeType.ADDED; @@ -70,6 +71,34 @@ export class NsfwWatcherService implements IWatcherService { } }); + // NSFW does not report file changes in the path provided on macOS if + // - the path uses wrong casing + // - the path is a symbolic link + // We have to detect this case and massage the events to correct this. + let realBasePathDiffers = false; + let realBasePathLength = request.basePath.length; + if (platform.isMacintosh) { + try { + + // First check for symbolic link + let realBasePath = realpathSync(request.basePath); + + // Second check for casing difference + if (request.basePath === realBasePath) { + realBasePath = (realcaseSync(request.basePath) || request.basePath); + } + + if (request.basePath !== realBasePath) { + realBasePathLength = realBasePath.length; + realBasePathDiffers = true; + + console.warn(`Watcher basePath does not match version on disk and will be corrected (original: ${request.basePath}, real: ${realBasePath})`); + } + } catch (error) { + // ignore + } + } + nsfw(request.basePath, events => { for (let i = 0; i < events.length; i++) { const e = events[i]; @@ -114,9 +143,17 @@ export class NsfwWatcherService implements IWatcherService { const events = undeliveredFileEvents; undeliveredFileEvents = []; - // Mac uses NFD unicode form on disk, but we want NFC if (platform.isMacintosh) { - events.forEach(e => e.path = normalizeNFC(e.path)); + events.forEach(e => { + + // Mac uses NFD unicode form on disk, but we want NFC + e.path = normalizeNFC(e.path); + + // Convert paths back to original form in case it differs + if (realBasePathDiffers) { + e.path = request.basePath + e.path.substr(realBasePathLength); + } + }); } // Broadcast to clients normalized