Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [flux-dev] Status update

For example, when I edit file on my linux machine, gnome editor creates temporary file and on saving it moves temporary file replacing original one. From java fs watcher's perspective it looks like a new file was created with the same name. Flux cannot handle this.
I think, this case can be handled using the same way, as flux handles changing existing files. What do you think?
I just tried to reproduce this issue on different machines. On Windows machine, when I try replace file, I get this sequence:
"ENTRY_DELETE
ENTRY_CREATE
ENTRY_MODIFY"
On latest linux kernel I have the same behavior. On unbuntu LTS, I get "ENTRY_CREATE" only. 
So, it looks like kernel issue. Martin, could you have a look at Mac machine, if it is possible?
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class App {

    public static void main(String[] args) throws InterruptedException, IOException {
        Path path = Paths.get(args[0]);
        WatchService ew = FileSystems.getDefault().newWatchService();

        WatchService wc = path.getFileSystem().newWatchService();
        path.register(wc, StandardWatchEventKinds.ENTRY_CREATE,
                StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);

        while (true) {
            WatchKey key = wc.poll(20, TimeUnit.SECONDS);
            if (key == null) {
                continue;
            }
            List<WatchEvent<?>> list = key.pollEvents();
            for (WatchEvent<?> w1 : list) {

                switch (w1.kind().name()) {
                case "ENTRY_CREATE":
                    System.out.println(w1.context() + " " + w1.kind());
                    break;
                case "ENTRY_DELETE":
                    System.out.println(w1.context() + " " + w1.kind());
                    break;
                case "ENTRY_MODIFY":
                    System.out.println(w1.context() + " " + w1.kind());
                    break;
                }
            }
            key.reset();
        }
    }
}

Back to the top