Skip to content

Commit

Permalink
fix #2566: report fs events for real paths
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Mar 28, 2019
1 parent 5ee68e0 commit a4a1541
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ export class NsfwFileSystemWatcherServer implements FileSystemWatcherServer {
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.ChangeEvent[]) => {
for (const event of events) {
if (event.action === nsfw.actions.CREATED) {
this.pushAdded(watcherId, paths.join(event.directory, event.file!));
this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));
}
if (event.action === nsfw.actions.DELETED) {
this.pushDeleted(watcherId, paths.join(event.directory, event.file!));
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file!));
}
if (event.action === nsfw.actions.MODIFIED) {
this.pushUpdated(watcherId, paths.join(event.directory, event.file!));
this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file!));
}
if (event.action === nsfw.actions.RENAMED) {
this.pushDeleted(watcherId, paths.join(event.directory, event.oldFile!));
this.pushAdded(watcherId, paths.join(event.directory, event.newFile!));
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile!));
this.pushAdded(watcherId, this.resolvePath(event.directory, event.newFile!));
}
}
});
Expand Down Expand Up @@ -192,6 +192,21 @@ export class NsfwFileSystemWatcherServer implements FileSystemWatcherServer {
this.fireDidFilesChanged();
}

protected resolvePath(directory: string, file: string): string {
const path = paths.join(directory, file);
try {
return fs.realpathSync(path);
} catch {
try {
// file does not exist try to resolve directory
return paths.join(fs.realpathSync(directory), file);
} catch {
// directory does not exist fall back to symlink
return path;
}
}
}

/**
* Fires file changes to clients.
* It is debounced in the case if the filesystem is spamming to avoid overwhelming clients with events.
Expand Down

0 comments on commit a4a1541

Please sign in to comment.