What to expect when a directory is moved?
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- java
调研方向
先从 JDKDirectoryWatch 和 JDKFileTreeWatch 开始,然后在相关平台上使用各种 Overflow 策略运行附录中的 Main 实验。将观察到的移动事件与所述的 Must 和 Should 要求进行比较;完成这项工作需要达成一致的行为,并有相应的实现或已记录的设计,但 issue 没有指出测试。
由索引模型根据 Issue 内容生成。
描述
Problem
If a non-empty directory is moved from one location in the scope of a recursive watch (the source) to another location in the scope (the target), then at least which events should be observable?
- 1.
DELETEDof the source - 2.
CREATEDof the target - 3.
DELETEDof each content item of the source - 4.
CREATEDof each content item of the target
(A solution to this problem probably becomes more complicated when the content items are themselves non-empty directories, but ignore that "detail" for now...)
Analysis
There is some variety in what currently (main, ec14259) happens, depending on the platform and overflow strategy:
| platform | overflow strategy | which events? |
|---|---|---|
| Windows | NONE, ALL, DIFF | 1+2 |
| macOS | NONE, ALL | 1+2 |
| macOS | DIFF | 1+2(+3)+4 |
Notes:
- Windows does supports passing modifier
ExtendedWatchEventModifier.FILE_TREEtoPath.register(...), so the library uses a single file-tree watch (JDKDirectoryWatchwhererecursiveis true). macOS doesn't support this, so the library uses a tree of single-directory watches (JDKFileTreeWatch). - The "(+3)" in the macOS-DIFF row indicates that, logically, it should also generate
DELETEDevents, but due to a bug, it doesn't. This doesn't affect the bigger point of this issue, though. - I haven't tested on Linux, but I expect it to be the same as on macOS.
Toward a design
I think the following requirements would make sense:
- "Must":
- 1+2
- If 3, then 4
- If 4, then 3
- "Should":
- 3+4
Achieving the "should" using a single file-tree watch on Windows seems quite messy. (We would need to do a lot of extra bookkeeping that might defeat the purpose of using the single file-tree watch in the first place.) An alternative path forward could be to always use a tree of single-directory watches. However, even in that case, the issue remains that it would work only for overflow strategy DIFF. Long story short, I don't think there's an easy fix here, and perhaps some more extensive redesign is needed.
Appendix: Experiments
Code
package engineering.swat.watch;
import java.io.IOException;
import java.nio.file.Files;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
for (var whichFiles : Approximation.values()) {
System.out.println();
System.out.println("-- Overflow strategy: " + whichFiles + " --");
System.out.println();
// Create file tree
var parent = Files.createTempDirectory("");
var child1 = Files.createDirectories(parent.resolve("from"));
var child2 = Files.createDirectories(parent.resolve("to"));
// Create directory to be moved
var directory = Files.createDirectory(child1.resolve("directory"));
Files.createFile(directory.resolve("file1.txt"));
Files.createFile(directory.resolve("file2.txt"));
// Start a watch for the whole file tree
try (var watch = Watch
.build(parent, WatchScope.PATH_AND_ALL_DESCENDANTS)
.onOverflow(whichFiles)
.on(System.out::println)
.start()) {
// Move directory
var source = child1.resolve(directory.getFileName());
var target = child2.resolve(directory.getFileName());
Files.move(source, target);
// Wait for events
Thread.sleep(30000);
}
}
System.exit(0);
}
}
Data: Windows
-- Overflow strategy: NONE --
WatchEvent[C:\Users\sung-\AppData\Local\Temp\6731006847162901629, MODIFIED, from\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\6731006847162901629, DELETED, from\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\6731006847162901629, CREATED, to\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\6731006847162901629, MODIFIED, to]
-- Overflow strategy: ALL --
WatchEvent[C:\Users\sung-\AppData\Local\Temp\8880121093523188257, MODIFIED, from\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\8880121093523188257, DELETED, from\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\8880121093523188257, CREATED, to\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\8880121093523188257, MODIFIED, to]
-- Overflow strategy: DIFF --
WatchEvent[C:\Users\sung-\AppData\Local\Temp\15514851762373591259, DELETED, from\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\15514851762373591259, CREATED, to\directory]
WatchEvent[C:\Users\sung-\AppData\Local\Temp\15514851762373591259, MODIFIED, to]
Data: macOS
-- Overflow strategy: NONE --
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/16128028026906265986, CREATED, to/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/16128028026906265986, MODIFIED, from]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/16128028026906265986, DELETED, from/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/16128028026906265986, MODIFIED, to]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/16128028026906265986, OVERFLOW, to/directory]
-- Overflow strategy: ALL --
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, DELETED, from/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, MODIFIED, from]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, MODIFIED, to]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, CREATED, to/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, OVERFLOW, to/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, CREATED, to/directory/file2.txt]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/6607535855848809431, CREATED, to/directory/file1.txt]
-- Overflow strategy: DIFF --
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, MODIFIED, from]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, DELETED, from/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, CREATED, to/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, MODIFIED, to]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, OVERFLOW, to/directory]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, CREATED, to/directory/file2.txt]
WatchEvent[/var/folders/k3/fpm2wy9s6l16x1cchqr9k7wh0000gn/T/3395878405261375498, CREATED, to/directory/file1.txt]
- 主要语言
- Java
- 星标
- 1
- 派生
- 0
- 平均合并
- 14 小时 40 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SWAT-engineering/java-watch 的其他 Issue
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
-
enhancement
难度 5/5 一周以上 新手友好度 28/100
-
`IndexingRescanner` doesn't generate `DELETED` events for content items of moved/renamed directories 未关闭bug
难度 3/5 1-2 天 新手友好度 45/100
-
good first issue
难度 3/5 1-2 天 新手友好度 42/100
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
查看 SWAT-engineering/java-watch 的全部 Issue
相似的 Issue
-
Bug Java Platform: Java
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-java#6138 · 1 条评论 ·
-
bug needs triage p2
难度 2/5 1-3 小时 新手友好度 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 条评论 ·
-
[Studio][Bug] Bulk-deleting a full page of alert rules steps the page back while more rules remain 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
apache/rocketmq-dashboard#4654 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 76/100