chokidar - ignore *.asar by default

This commit is contained in:
Benjamin Pasero 2019-10-14 15:28:19 +02:00
parent e06de411d2
commit 21cda4e0f0

View file

@ -19,6 +19,8 @@ import { IWatcherRequest, IWatcherService, IWatcherOptions } from 'vs/platform/f
import { Emitter, Event } from 'vs/base/common/event';
import { equals } from 'vs/base/common/arrays';
process.noAsar = true; // disable ASAR support in watcher process
interface IWatcher {
requests: ExtendedWatcherRequest[];
stop(): any;
@ -50,29 +52,30 @@ export class ChokidarWatcherService implements IWatcherService {
private readonly _onLogMessage = new Emitter<ILogMessage>();
readonly onLogMessage: Event<ILogMessage> = this._onLogMessage.event;
public watch(options: IWatcherOptions): Event<IDiskFileChange[]> {
watch(options: IWatcherOptions): Event<IDiskFileChange[]> {
this._pollingInterval = options.pollingInterval;
this._usePolling = options.usePolling;
this._watchers = Object.create(null);
this._watcherCount = 0;
return this.onWatchEvent;
}
public setVerboseLogging(enabled: boolean): Promise<void> {
setVerboseLogging(enabled: boolean): Promise<void> {
this._verboseLogging = enabled;
return Promise.resolve();
}
public setRoots(requests: IWatcherRequest[]): Promise<void> {
setRoots(requests: IWatcherRequest[]): Promise<void> {
const watchers = Object.create(null);
const newRequests: string[] = [];
const requestsByBasePath = normalizeRoots(requests);
// evaluate new & remaining watchers
for (let basePath in requestsByBasePath) {
let watcher = this._watchers[basePath];
for (const basePath in requestsByBasePath) {
const watcher = this._watchers[basePath];
if (watcher && isEqualRequests(watcher.requests, requestsByBasePath[basePath])) {
watchers[basePath] = watcher;
delete this._watchers[basePath];
@ -80,13 +83,15 @@ export class ChokidarWatcherService implements IWatcherService {
newRequests.push(basePath);
}
}
// stop all old watchers
for (let path in this._watchers) {
for (const path in this._watchers) {
this._watchers[path].stop();
}
// start all new watchers
for (let basePath of newRequests) {
let requests = requestsByBasePath[basePath];
for (const basePath of newRequests) {
const requests = requestsByBasePath[basePath];
watchers[basePath] = this._watch(basePath, requests);
}
@ -95,7 +100,7 @@ export class ChokidarWatcherService implements IWatcherService {
}
// for test purposes
public get wacherCount() {
get wacherCount() {
return this._watcherCount;
}
@ -121,9 +126,10 @@ export class ChokidarWatcherService implements IWatcherService {
};
const excludes: string[] = [];
// if there's only one request, use the built-in ignore-filterering
const isSingleFolder = requests.length === 1;
if (isSingleFolder) {
// if there's only one request, use the built-in ignore-filterering
excludes.push(...requests[0].excludes);
}
@ -133,6 +139,9 @@ export class ChokidarWatcherService implements IWatcherService {
excludes.push('/proc/**', '/sys/**');
}
}
excludes.push('**/*.asar'); // Ensure we never recurse into ASAR archives
watcherOpts.ignored = excludes;
// Chokidar fails when the basePath does not match case-identical to the path on disk
@ -220,7 +229,7 @@ export class ChokidarWatcherService implements IWatcherService {
}
}
let event = { type: eventType, path };
const event = { type: eventType, path };
// Logging
if (this._verboseLogging) {
@ -284,12 +293,14 @@ export class ChokidarWatcherService implements IWatcherService {
return watcher;
}
public stop(): Promise<void> {
for (let path in this._watchers) {
let watcher = this._watchers[path];
stop(): Promise<void> {
for (const path in this._watchers) {
const watcher = this._watchers[path];
watcher.stop();
}
this._watchers = Object.create(null);
return Promise.resolve();
}
@ -307,25 +318,28 @@ export class ChokidarWatcherService implements IWatcherService {
}
function isIgnored(path: string, requests: ExtendedWatcherRequest[]): boolean {
for (let request of requests) {
for (const request of requests) {
if (request.path === path) {
return false;
}
if (extpath.isEqualOrParent(path, request.path)) {
if (!request.parsedPattern) {
if (request.excludes && request.excludes.length > 0) {
let pattern = `{${request.excludes.join(',')}}`;
const pattern = `{${request.excludes.join(',')}}`;
request.parsedPattern = glob.parse(pattern);
} else {
request.parsedPattern = () => false;
}
}
const relPath = path.substr(request.path.length + 1);
if (!request.parsedPattern(relPath)) {
return false;
}
}
}
return true;
}
@ -335,11 +349,12 @@ function isIgnored(path: string, requests: ExtendedWatcherRequest[]): boolean {
*/
export function normalizeRoots(requests: IWatcherRequest[]): { [basePath: string]: IWatcherRequest[] } {
requests = requests.sort((r1, r2) => r1.path.localeCompare(r2.path));
let prevRequest: IWatcherRequest | null = null;
let result: { [basePath: string]: IWatcherRequest[] } = Object.create(null);
for (let request of requests) {
let basePath = request.path;
let ignored = (request.excludes || []).sort();
const result: { [basePath: string]: IWatcherRequest[] } = Object.create(null);
for (const request of requests) {
const basePath = request.path;
const ignored = (request.excludes || []).sort();
if (prevRequest && (extpath.isEqualOrParent(basePath, prevRequest.path))) {
if (!isEqualIgnore(ignored, prevRequest.excludes)) {
result[prevRequest.path].push({ path: basePath, excludes: ignored });
@ -349,6 +364,7 @@ export function normalizeRoots(requests: IWatcherRequest[]): { [basePath: string
result[basePath] = [prevRequest];
}
}
return result;
}