@@ -40,7 +40,7 @@ fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Resul
40
40
/// Watch a file or directory, sending relevant events through the provided channel.
41
41
async fn async_watch < P : AsRef < Path > > (
42
42
path : P ,
43
- mut event_tx : UnboundedSender < ( ) > ,
43
+ mut change_tx : UnboundedSender < ( ) > ,
44
44
) -> Result < ( ) , Box < dyn Error > > {
45
45
let path = path. as_ref ( ) ;
46
46
let path = std:: fs:: canonicalize ( path)
@@ -50,7 +50,12 @@ async fn async_watch<P: AsRef<Path>>(
50
50
51
51
// Add a path to be watched. All files and directories at that path and
52
52
// below will be monitored for changes.
53
- watcher. watch ( path. as_ref ( ) , RecursiveMode :: Recursive ) ?;
53
+ let watch_path = if path. is_dir ( ) {
54
+ path. clone ( )
55
+ } else {
56
+ path. parent ( ) . unwrap ( ) . to_owned ( )
57
+ } ;
58
+ watcher. watch ( watch_path. as_ref ( ) , RecursiveMode :: Recursive ) ?;
54
59
55
60
while let Some ( res) = rx. next ( ) . await {
56
61
match res {
@@ -59,14 +64,10 @@ async fn async_watch<P: AsRef<Path>>(
59
64
|| event
60
65
. paths
61
66
. iter ( )
62
- . find ( |candidate| {
63
- std:: fs:: canonicalize ( candidate) . unwrap_or_else ( |e| {
64
- panic ! ( "Failed to canonicalize path {path:?}: {e:}" )
65
- } ) == path
66
- } )
67
+ . find ( |candidate| * * candidate == path)
67
68
. is_some ( )
68
69
{
69
- event_tx . send ( ( ) ) . await . unwrap ( ) ;
70
+ change_tx . send ( ( ) ) . await . unwrap ( ) ;
70
71
}
71
72
}
72
73
Err ( e) => error ! ( "Watch error: {:?}" , e) ,
0 commit comments