1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix: support "other" event type in FSWatcher (#12836)

This commit adds support for "other" events in `FSWatcher`. Flags on
events are now exposed via the `flag` property  on `FsEvent`.
This commit is contained in:
Luca Casonato 2021-11-23 11:30:24 +01:00 committed by GitHub
parent 2eae1ae665
commit ae34f8fa10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View file

@ -2007,9 +2007,23 @@ declare namespace Deno {
*/ */
export function resources(): ResourceMap; export function resources(): ResourceMap;
/**
* Additional information for FsEvent objects with the "other" kind.
*
* - "rescan": rescan notices indicate either a lapse in the events or a
* change in the filesystem such that events received so far can no longer
* be relied on to represent the state of the filesystem now. An
* application that simply reacts to file changes may not care about this.
* An application that keeps an in-memory representation of the filesystem
* will need to care, and will need to refresh that representation directly
* from the filesystem.
*/
export type FsEventFlag = "rescan";
export interface FsEvent { export interface FsEvent {
kind: "any" | "access" | "create" | "modify" | "remove"; kind: "any" | "access" | "create" | "modify" | "remove" | "other";
paths: string[]; paths: string[];
flag?: FsEventFlag;
} }
/** /**

View file

@ -65,8 +65,9 @@ impl Resource for FsEventsResource {
/// the complexity. /// the complexity.
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
struct FsEvent { struct FsEvent {
kind: String, kind: &'static str,
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
flag: Option<&'static str>,
} }
impl From<NotifyEvent> for FsEvent { impl From<NotifyEvent> for FsEvent {
@ -77,12 +78,15 @@ impl From<NotifyEvent> for FsEvent {
EventKind::Create(_) => "create", EventKind::Create(_) => "create",
EventKind::Modify(_) => "modify", EventKind::Modify(_) => "modify",
EventKind::Remove(_) => "remove", EventKind::Remove(_) => "remove",
EventKind::Other => todo!(), // What's this for? Leaving it out for now. EventKind::Other => "other",
} };
.to_string(); let flag = e.flag().map(|f| match f {
notify::event::Flag::Rescan => "rescan",
});
FsEvent { FsEvent {
kind, kind,
paths: e.paths, paths: e.paths,
flag,
} }
} }
} }