提交 2b4a8c02 编写于 作者: B Benjamin Pasero

fix #46538

上级 4380358c
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册