Skip to content

Commit 9b58bc4

Browse files
committed
Revert change to relativize in JDKFileTreeWatch (and add comment for usage assumption)
1 parent b760db9 commit 9b58bc4

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/main/java/engineering/swat/watch/impl/jdk/JDKFileTreeWatch.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.file.Path;
3333
import java.util.HashSet;
3434
import java.util.Map;
35+
import java.util.Objects;
3536
import java.util.concurrent.ConcurrentHashMap;
3637
import java.util.concurrent.Executor;
3738
import java.util.function.BiConsumer;
@@ -76,18 +77,16 @@ public JDKFileTreeWatch(Path rootPath, Path relativePathParent, Executor exec,
7677
// `rootPath` (instead of `path`, as is the default behavior)
7778
@Override
7879
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));
9190
}
9291

9392
// Override to ensure that this watch translates JDK events using

0 commit comments

Comments
 (0)