Skip to content

Commit

Permalink
“Visual Studio Code” would like to access data from other apps. (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Sep 2, 2024
1 parent 21135c8 commit 6e8e175
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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<IWatcherErrorEvent>());
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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}'`);
Expand All @@ -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;
Expand Down

0 comments on commit 6e8e175

Please sign in to comment.