SWAT-engineering / SWAT-engineering/java-watch
What to expect when a directory is moved?
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 1
- Forks
- 0
- Merge moyen
- 14 h 40 min
- PR mergées (30 j)
- 1
Description
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]
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par JDKDirectoryWatch et JDKFileTreeWatch, puis exécutez l’expérience Main de l’annexe sur les plateformes concernées et avec les différentes stratégies d’Overflow. Comparez les événements de déplacement observés aux exigences Must et Should énoncées ; la tâche ne peut être considérée comme terminée que lorsqu’un comportement convenu ainsi qu’une implémentation correspondante ou une conception documentée existent, mais l’issue n’identifie pas de tests.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- operating-systems
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100