| 446 | tryPromise("utimes", path, () => Deno.utime(path, atime, mtime)) |
| 447 | |
| 448 | const watchNative = ( |
| 449 | path: string, |
| 450 | options?: FileSystem.WatchOptions |
| 451 | ): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> => |
| 452 | Stream.unwrap( |
| 453 | Effect.map( |
| 454 | Effect.try({ |
| 455 | try: () => Deno.watchFs(path, { recursive: options?.recursive ?? false }), |
| 456 | catch: handleError("FileSystem", "watch", path) |
| 457 | }), |
| 458 | (watcher) => { |
| 459 | options?.onReady?.() |
| 460 | return Stream.fromAsyncIterable(watcher, handleError("FileSystem", "watch", path)).pipe( |
| 461 | Stream.flatMap((event): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> => { |
| 462 | switch (event.kind) { |
| 463 | case "create": |
| 464 | return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Create" as const, path })) |
| 465 | case "modify": |
| 466 | return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Update" as const, path })) |
| 467 | case "remove": |
| 468 | return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Remove" as const, path })) |
| 469 | case "rename": |
| 470 | return Stream.mapEffect(Stream.fromIterable(event.paths), (path) => |
| 471 | Effect.match(stat(path), { |
| 472 | onFailure: () => ({ _tag: "Remove" as const, path }), |
| 473 | onSuccess: () => ({ _tag: "Create" as const, path }) |
| 474 | })) |
| 475 | default: |
| 476 | return Stream.empty |
| 477 | } |
| 478 | }) |
| 479 | ) |
| 480 | } |
| 481 | ) |
| 482 | ) |
| 483 | |
| 484 | const watch = ( |
| 485 | backend: Option.Option<FileSystem.WatchBackend["Service"]>, |