|
33 | 33 | import static engineering.swat.watch.impl.mac.apis.FileSystemEvents.FSEventStreamEventFlag.ITEM_INODE_META_MOD; |
34 | 34 | import static engineering.swat.watch.impl.mac.apis.FileSystemEvents.FSEventStreamEventFlag.ITEM_MODIFIED; |
35 | 35 | import static engineering.swat.watch.impl.mac.apis.FileSystemEvents.FSEventStreamEventFlag.ITEM_REMOVED; |
| 36 | +import static engineering.swat.watch.impl.mac.apis.FileSystemEvents.FSEventStreamEventFlag.ITEM_RENAMED; |
36 | 37 | import static engineering.swat.watch.impl.mac.apis.FileSystemEvents.FSEventStreamEventFlag.MUST_SCAN_SUB_DIRS; |
37 | 38 | import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; |
38 | 39 | import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; |
|
41 | 42 |
|
42 | 43 | import java.io.Closeable; |
43 | 44 | import java.io.IOException; |
| 45 | +import java.nio.file.Files; |
44 | 46 | import java.nio.file.Path; |
45 | 47 | import java.util.Arrays; |
46 | 48 |
|
@@ -153,6 +155,19 @@ public void callback(Pointer streamRef, Pointer clientCallBackInfo, |
153 | 155 | if (any(flags[i], MUST_SCAN_SUB_DIRS.mask)) { |
154 | 156 | handler.handle(OVERFLOW, null); |
155 | 157 | } |
| 158 | + if (any(flags[i], ITEM_RENAMED.mask)) { |
| 159 | + // For now, check if the file exists to determine if the |
| 160 | + // event pertains to the target of the rename (if it |
| 161 | + // exists) or to the source (else). This is an |
| 162 | + // approximation. It might be more accurate to maintain |
| 163 | + // an internal index (but getting the concurrency right |
| 164 | + // requires care). |
| 165 | + if (Files.exists(Path.of(paths[i]))) { |
| 166 | + handler.handle(ENTRY_CREATE, context); |
| 167 | + } else { |
| 168 | + handler.handle(ENTRY_DELETE, context); |
| 169 | + } |
| 170 | + } |
156 | 171 | } |
157 | 172 | } |
158 | 173 |
|
|
0 commit comments