@@ -11,7 +11,7 @@ use kotars::jni_init;
11
11
use libssh_rs:: { PollStatus , SshOption } ;
12
12
#[ allow( unused_imports) ]
13
13
use libssh_rs:: AuthStatus ;
14
- use notify:: { Config , Error , ErrorKind , Event , RecommendedWatcher , RecursiveMode , Watcher } ;
14
+ use notify:: { Config , Error , ErrorKind , Event , EventKind , RecommendedWatcher , RecursiveMode , Watcher } ;
15
15
16
16
jni_init ! ( "" ) ;
17
17
@@ -102,7 +102,7 @@ impl FileWatcher {
102
102
last_update = current_time_as_millis ( ) ;
103
103
}
104
104
105
- // println!("Event: {e:?}");
105
+ println ! ( "Event: {e:?}" ) ;
106
106
}
107
107
}
108
108
Err ( e) => {
@@ -172,36 +172,17 @@ fn error_to_code(error_kind: ErrorKind) -> i32 {
172
172
pub fn get_paths_from_event_result ( event_result : & Result < Event , Error > , git_dir_path : & str ) -> Option < Vec < String > > {
173
173
match event_result {
174
174
Ok ( event) => {
175
- let events: Vec < String > = event
176
- . paths
177
- . clone ( )
178
- . into_iter ( )
179
- . filter_map ( |path| {
180
- // Directories are not tracked by Git so we don't care about them (just about their content)
181
- // We won't be able to check if it's a dir if it has been deleted but that's good enough
182
- // if path.is_dir() {
183
- // println!("Ignoring directory {path:#?}");
184
- // None
185
- // } else {
186
- let path_str = path. into_os_string ( )
187
- . into_string ( )
188
- . ok ( ) ?;
189
-
190
- // JGit may create .probe-UUID files for its internal stuff, we don't care about it
191
- let probe_prefix = format ! ( "{git_dir_path}.probe-" ) ;
192
- if path_str. starts_with ( probe_prefix. as_str ( ) ) {
175
+ match event. kind {
176
+ EventKind :: Create ( _) | EventKind :: Modify ( _) | EventKind :: Remove ( _) => {
177
+ let events: Vec < String > = get_event_paths ( event, git_dir_path) ;
178
+
179
+ if events. is_empty ( ) {
193
180
None
194
181
} else {
195
- Some ( path_str )
182
+ Some ( events )
196
183
}
197
- // }
198
- } )
199
- . collect ( ) ;
200
-
201
- if events. is_empty ( ) {
202
- None
203
- } else {
204
- Some ( events)
184
+ }
185
+ _ => { None }
205
186
}
206
187
}
207
188
Err ( err) => {
@@ -211,6 +192,33 @@ pub fn get_paths_from_event_result(event_result: &Result<Event, Error>, git_dir_
211
192
}
212
193
}
213
194
195
+ fn get_event_paths ( event : & Event , git_dir_path : & str ) -> Vec < String > {
196
+ event
197
+ . paths
198
+ . clone ( )
199
+ . into_iter ( )
200
+ . filter_map ( |path| {
201
+ // Directories are not tracked by Git so we don't care about them (just about their content)
202
+ // We won't be able to check if it's a dir if it has been deleted but that's good enough
203
+ // if path.is_dir() {
204
+ // println!("Ignoring directory {path:#?}");
205
+ // None
206
+ // } else {
207
+ let path_str = path. into_os_string ( )
208
+ . into_string ( )
209
+ . ok ( ) ?;
210
+
211
+ // JGit may create .probe-UUID files for its internal stuff, we don't care about it
212
+ let probe_prefix = format ! ( "{git_dir_path}.probe-" ) ;
213
+ if path_str. starts_with ( probe_prefix. as_str ( ) ) {
214
+ None
215
+ } else {
216
+ Some ( path_str)
217
+ }
218
+ // }
219
+ } )
220
+ . collect ( )
221
+ }
214
222
#[ jni_interface]
215
223
pub trait WatchDirectoryNotifier {
216
224
fn should_keep_looping ( & self ) -> bool ;
0 commit comments