-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix slint-viewer --auto-reload for editors which rename and replace files #5094
Conversation
I think watching the parent directory is too much. If some random files is being created in that directory, we don't want to reload the view. |
Tested manually using the attached files. It wasn't clear to me how best to test this in Rust. I could provide my own fswatch thread, but that would be testing that, rather than the existing thread. |
I had reservations about this too. I'll see what I can do. |
Updated test scripts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I added a few comments.
Some editors, such as vim, rename (move) a file to a backup location, then write the new contents to a new location when the user saves their changes. notify stops watching the renamed file, and does not automatically start watching the new file created. Additionally, slint-viewer attempts to reload before the editor has written the new file, which causes an error. The file is then never reloaded because the watcher was lost. This patch solves the problem by attempting to watch the file again, if the previous watch failed due to a Generic or PathNotFound error. Generic is required because this is error type we get on macOS for "No such file or directory.". We delay the retry by a small timeout to give the editor a chance to write the new file. Note that this still results in an error being printed about the missing file. Tested manually by editing both root .slint file, and .slint files imported from sub-directories. Closes: slint-ui#3641
9b329d7
to
67a720c
Compare
I found that watching the parent directory wasn't sufficient for the first edit, but would work fine for subsequent edits. My test scripts essentially hid this problem. In hind-sight it is possible that this is due to However, the new approach to retrying the watch is simpler, and works for all edits I make to the file. |
I don't understand anymore how this works. My understanding was that we were watching the file |
My understanding is as follows:
This patch works because thanks to the retry, the events continue as follows: As an alternative to the single shot timer, we could recursively watch the parent directory of |
I see, thanks for the explanations. @tronical , does it make sense to you? |
The risks of this patch are:
Recursively watching the parent directory would avoid these issues, however it is not necessarily fool proof either. Notify has a number of known problems including reaching the max-files watch limit and failure to receive all events when watching very large directories. |
Sounds like a reasonable workaround to me. |
I'm a bit skeptical, but if you say this solves the problem, let's merge it. |
@ogoffart Would you like to see the watch parent approach? |
I think it's fine as is, no need to overthink it. If the problem is solved this is good enough. |
Some editors may backup a file by renaming it to append ~, then saving the new file contents to a new file. notify-rs/notify#166 explains that a non-recursive watcher on the parent directory is the recommended way to deal with this situation.
Closes: #3641