|
32 | 32 | import java.nio.file.Path; |
33 | 33 | import java.util.HashSet; |
34 | 34 | import java.util.Map; |
| 35 | +import java.util.Objects; |
35 | 36 | import java.util.concurrent.ConcurrentHashMap; |
36 | 37 | import java.util.concurrent.Executor; |
37 | 38 | import java.util.function.BiConsumer; |
@@ -76,18 +77,16 @@ public JDKFileTreeWatch(Path rootPath, Path relativePathParent, Executor exec, |
76 | 77 | // `rootPath` (instead of `path`, as is the default behavior) |
77 | 78 | @Override |
78 | 79 | public WatchEvent relativize(WatchEvent event) { |
79 | | - var relativePath = relativePathParent; |
80 | | - |
81 | | - // Append a file name to `relativePath` if it exists |
82 | | - var fullPath = event.calculateFullPath(); |
83 | | - if (!fullPath.equals(path)) { |
84 | | - var fileName = fullPath.getFileName(); |
85 | | - if (fileName != null) { |
86 | | - relativePath = relativePath.resolve(fileName); |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - return new WatchEvent(event.getKind(), rootPath, relativePath); |
| 80 | + // Assumption: The parent of the full path of `event` and the |
| 81 | + // path of this watch are the same, so we only need to append |
| 82 | + // the file name of `event` to relativize. |
| 83 | + assert Objects.equals( |
| 84 | + event.calculateFullPath().getParent(), |
| 85 | + rootPath.resolve(relativePathParent)); |
| 86 | + |
| 87 | + var fileName = event.getFileName(); |
| 88 | + return new WatchEvent(event.getKind(), rootPath, |
| 89 | + fileName == null ? relativePathParent : relativePathParent.resolve(fileName)); |
91 | 90 | } |
92 | 91 |
|
93 | 92 | // Override to ensure that this watch translates JDK events using |
|
0 commit comments