From 6e8e1758574766a7c67cc22a0ced1c104347fac3 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 2 Sep 2024 21:09:47 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9CVisual=20Studio=20Code=E2=80=9D=20woul?= =?UTF-8?q?d=20like=20to=20access=20data=20from=20other=20apps.=20(fix=20#?= =?UTF-8?q?208105)=20(#227407)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/watcher/parcel/parcelWatcher.ts | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts b/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts index 1446312fa7661..40ba97326039d 100644 --- a/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts +++ b/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts @@ -5,7 +5,7 @@ import * as parcelWatcher from '@parcel/watcher'; import { existsSync, statSync, unlinkSync } from 'fs'; -import { tmpdir } from 'os'; +import { tmpdir, homedir } from 'os'; import { URI } from '../../../../../base/common/uri.js'; import { DeferredPromise, RunOnceScheduler, RunOnceWorker, ThrottledWorker } from '../../../../../base/common/async.js'; import { CancellationToken, CancellationTokenSource } from '../../../../../base/common/cancellation.js'; @@ -16,7 +16,7 @@ import { GLOBSTAR, patternsEquals } from '../../../../../base/common/glob.js'; import { BaseWatcher } from '../baseWatcher.js'; import { TernarySearchTree } from '../../../../../base/common/ternarySearchTree.js'; import { normalizeNFC } from '../../../../../base/common/normalization.js'; -import { dirname, normalize } from '../../../../../base/common/path.js'; +import { dirname, normalize, join } from '../../../../../base/common/path.js'; import { isLinux, isMacintosh, isWindows } from '../../../../../base/common/platform.js'; import { realcaseSync, realpathSync } from '../../../../../base/node/extpath.js'; import { NodeJSFileWatcherLibrary } from '../nodejs/nodejsWatcherLib.js'; @@ -145,6 +145,14 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS ] ); + private static readonly PREDEFINED_EXCLUDES: { [platform: string]: string[] } = { + 'win32': [], + 'darwin': [ + join(homedir(), 'Library', 'Containers') // Triggers access dialog from macOS 14 (https://github.com/microsoft/vscode/issues/208105) + ], + 'linux': [] + }; + private static readonly PARCEL_WATCHER_BACKEND = isWindows ? 'windows' : isLinux ? 'inotify' : 'fs-events'; private readonly _onDidError = this._register(new Emitter()); @@ -294,7 +302,7 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS // We already ran before, check for events since if (counter > 1) { - const parcelEvents = await parcelWatcher.getEventsSince(realPath, snapshotFile, { ignore: request.excludes, backend: ParcelWatcher.PARCEL_WATCHER_BACKEND }); + const parcelEvents = await parcelWatcher.getEventsSince(realPath, snapshotFile, { ignore: this.addPredefinedExcludes(request.excludes), backend: ParcelWatcher.PARCEL_WATCHER_BACKEND }); if (cts.token.isCancellationRequested) { return; @@ -305,7 +313,7 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS } // Store a snapshot of files to the snapshot file - await parcelWatcher.writeSnapshot(realPath, snapshotFile, { ignore: request.excludes, backend: ParcelWatcher.PARCEL_WATCHER_BACKEND }); + await parcelWatcher.writeSnapshot(realPath, snapshotFile, { ignore: this.addPredefinedExcludes(request.excludes), backend: ParcelWatcher.PARCEL_WATCHER_BACKEND }); // Signal we are ready now when the first snapshot was written if (counter === 1) { @@ -367,7 +375,7 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS this.onParcelEvents(parcelEvents, watcher, realPathDiffers, realPathLength); }, { backend: ParcelWatcher.PARCEL_WATCHER_BACKEND, - ignore: watcher.request.excludes + ignore: this.addPredefinedExcludes(watcher.request.excludes) }); this.trace(`Started watching: '${realPath}' with backend '${ParcelWatcher.PARCEL_WATCHER_BACKEND}'`); @@ -383,6 +391,21 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS } } + private addPredefinedExcludes(initialExcludes: string[]): string[] { + const excludes = [...initialExcludes]; + + const predefinedExcludes = ParcelWatcher.PREDEFINED_EXCLUDES[process.platform]; + if (Array.isArray(predefinedExcludes)) { + for (const exclude of predefinedExcludes) { + if (!excludes.includes(exclude)) { + excludes.push(exclude); + } + } + } + + return excludes; + } + private onParcelEvents(parcelEvents: parcelWatcher.Event[], watcher: ParcelWatcherInstance, realPathDiffers: boolean, realPathLength: number): void { if (parcelEvents.length === 0) { return;