Skip to content

Commit

Permalink
fix: will watch same folder multiple times (#3831)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain authored Jul 3, 2024
1 parent 4c1e2ec commit a8a96d3
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions packages/file-service/src/node/recursive/file-service-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface WatcherOptions {
excludes: string[];
}

const watcherPlaceHolder = {
disposable: {
dispose: () => {},
},
handlers: [],
};

/**
* @deprecated
*/
Expand Down Expand Up @@ -88,18 +95,24 @@ export class FileSystemWatcherServer implements IFileSystemWatcherServer {
*/
async watchFileChanges(uri: string, options?: WatchOptions): Promise<number> {
const basePath = FileUri.fsPath(uri);
const exist = await fs.pathExists(basePath);

let watcherId = this.checkIsAlreadyWatched(basePath);
if (watcherId) {
return watcherId;
}

watcherId = FileSystemWatcherServer.WATCHER_SEQUENCE++;
this.WATCHER_HANDLERS.set(watcherId, {
...watcherPlaceHolder,
path: basePath,
});

const toDisposeWatcher = new DisposableCollection();
let watchPath;
let watchPath: string;

const exist = await fs.pathExists(basePath);
if (exist) {
const stat = await fs.lstatSync(basePath);
const stat = await fs.lstat(basePath);
if (stat && stat.isDirectory()) {
watchPath = basePath;
} else {
Expand All @@ -116,14 +129,16 @@ export class FileSystemWatcherServer implements IFileSystemWatcherServer {
}
events = this.trimChangeEvent(events);
for (const event of events) {
if (event.type === 'create') {
this.pushAdded(event.path);
}
if (event.type === 'delete') {
this.pushDeleted(event.path);
}
if (event.type === 'update') {
this.pushUpdated(event.path);
switch (event.type) {
case 'create':
this.pushAdded(event.path);
break;
case 'delete':
this.pushDeleted(event.path);
break;
case 'update':
this.pushUpdated(event.path);
break;
}
}
};
Expand Down

0 comments on commit a8a96d3

Please sign in to comment.