提交 3a619f24 编写于 作者: B Benjamin Pasero

watcher - perf: parse globs for excludes

上级 1b6468ef
......@@ -29,7 +29,7 @@ interface IWatcherObjet {
interface IPathWatcher {
ready: TPromise<IWatcherObjet>;
watcher?: IWatcherObjet;
ignored: string[];
ignored: glob.ParsedPattern[];
}
export class NsfwWatcherService implements IWatcherService {
......@@ -54,7 +54,7 @@ export class NsfwWatcherService implements IWatcherService {
let readyPromiseCallback: TValueCallback<IWatcherObjet>;
this._pathWatchers[request.basePath] = {
ready: new TPromise<IWatcherObjet>(c => readyPromiseCallback = c),
ignored: request.ignored
ignored: Array.isArray(request.ignored) ? request.ignored.map(ignored => glob.parse(ignored)) : []
};
process.on('uncaughtException', (e: Error | string) => {
......@@ -171,7 +171,7 @@ export class NsfwWatcherService implements IWatcherService {
// Refresh ignored arrays in case they changed
roots.forEach(root => {
if (root.basePath in this._pathWatchers) {
this._pathWatchers[root.basePath].ignored = root.ignored;
this._pathWatchers[root.basePath].ignored = Array.isArray(root.ignored) ? root.ignored.map(ignored => glob.parse(ignored)) : [];
}
});
......@@ -188,7 +188,7 @@ export class NsfwWatcherService implements IWatcherService {
}));
}
private _isPathIgnored(absolutePath: string, ignored: string[]): boolean {
return ignored && ignored.some(ignore => glob.match(ignore, absolutePath));
private _isPathIgnored(absolutePath: string, ignored: glob.ParsedPattern[]): boolean {
return ignored && ignored.some(i => i(absolutePath));
}
}
......@@ -20,18 +20,26 @@ export class OutOfProcessWin32FolderWatcher {
private static changeTypeMap: FileChangeType[] = [FileChangeType.UPDATED, FileChangeType.ADDED, FileChangeType.DELETED];
private ignored: glob.ParsedPattern[];
private handle: cp.ChildProcess;
private restartCounter: number;
constructor(
private watchedFolder: string,
private ignored: string[],
ignored: string[],
private eventCallback: (events: IRawFileChange[]) => void,
private errorCallback: (error: string) => void,
private verboseLogging: boolean
) {
this.restartCounter = 0;
if (Array.isArray(ignored)) {
this.ignored = ignored.map(i => glob.parse(i));
} else {
this.ignored = [];
}
this.startWatcher();
}
......@@ -60,7 +68,7 @@ export class OutOfProcessWin32FolderWatcher {
if (changeType >= 0 && changeType < 3) {
// Support ignores
if (this.ignored && this.ignored.some(ignore => glob.match(ignore, absolutePath))) {
if (this.ignored && this.ignored.some(ignore => ignore(absolutePath))) {
if (this.verboseLogging) {
console.log('%c[File Watcher (C#)]', 'color: blue', ' >> ignored', absolutePath);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册