dora icon indicating copy to clipboard operation
dora copied to clipboard

Try to rewatch removed files in `--attach`

Open phil-opp opened this issue 1 year ago • 6 comments

Vim creates a new file inode when modifying files, which results in a 'remove' event. This commit handles this by treating 'remove' events as a trigger for reloads. After sending the reload command, the watcher now tries to watch the same path again, which watches the newly created file.

Fixes #530

phil-opp avatar Jun 04 '24 08:06 phil-opp

@hbuxiaofei Could you please try whether this PR fixes #530 for you?

phil-opp avatar Jun 04 '24 08:06 phil-opp

@hbuxiaofei Could you please try whether this PR fixes #530 for you?

Yes, this patch does work, but it needs to add the ModifyKind::Metadata and ModifyKind::Name events to work well.

EventKind::Modify(ModifyKind::Metadata(_)) => false,   
EventKind::Modify(ModifyKind::Name(_)) => true,        

Maybe it's because vim creates a temporary .xxx.swp file.

And there are some small problems, some warning logs will appear.

  2024-06-06T07:41:58.048671Z  WARN dora::attach: failed to watch `/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py` again: No such file or directory (os error 2) -> further modifications will be ignored
    at binaries/cli/src/attach.rs:114

hbuxiaofei avatar Jun 06 '24 07:06 hbuxiaofei

Thanks for testing!

And there are some small problems, some warning logs will appear.

Hmm, this warning indicates that the re-watching failed, so subsequent file changes will be ignored. So this is problematic. Do the warnings still occur after you added the ModifyKind::Metadata and ModifyKind::Name events?

phil-opp avatar Jun 06 '24 10:06 phil-opp

Thanks for testing!

And there are some small problems, some warning logs will appear.

Hmm, this warning indicates that the re-watching failed, so subsequent file changes will be ignored. So this is problematic. Do the warnings still occur after you added the ModifyKind::Metadata and ModifyKind::Name events?

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

hbuxiaofei avatar Jun 06 '24 11:06 hbuxiaofei

Could you post the relevant parts of your vim config. I'm trying to reproduce this, but I keep getting normal Modify events.

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

Adding ModifyKind::Name seems reasonable, but I'm not sure about ModifyKind::Metadata. Ideally, I want to avoid any watch errors if possible. Or alternatively, we could retry a failed watch operation if there is a race between the creation of the new file and the Remove event of the old file.

phil-opp avatar Jun 06 '24 14:06 phil-opp

Could you post the relevant parts of your vim config. I'm trying to reproduce this, but I keep getting normal Modify events.

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

Adding ModifyKind::Name seems reasonable, but I'm not sure about ModifyKind::Metadata. Ideally, I want to avoid any watch errors if possible. Or alternatively, we could retry a failed watch operation if there is a race between the creation of the new file and the Remove event of the old file.

Here is my vim configuration repository: https://github.com/hbuxiaofei/vimll

But I don't think it has anything to do with the configuration. I cleared my vim configuration and still received this events:

>>> recv events: Event { kind: Modify(Metadata(Any)), paths: ["/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
>>> recv events: Event { kind: Remove(File), paths: ["/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

Vim version :

$ vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Mar 31 2024 00:15:53)

hbuxiaofei avatar Jun 07 '24 02:06 hbuxiaofei