From 2b4a8c02b344835f8c0ece66e8542763dea97250 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 5 Sep 2018 15:19:57 +0200 Subject: [PATCH] fix #46538 --- .../node/watcher/nsfw/nsfwWatcherService.ts | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) 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 b05274d5856..d3ef72006c8 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 -- GitLab