-
Notifications
You must be signed in to change notification settings - Fork 331
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
Use fsnotify
for watching file updates
#1667
Conversation
This feature already works pretty well and I think it can merged now after the recent release to have more people test it. I didn't find any issues so far and while it adds a bit more code (and dependency) to lf, the solution looks a lot cleaner and covers more use cases then what I had in mind with #1671.
Actually chmod is listed on the fsnotify repo as a supported attribute and after a quick test with this patch it seems to already cover permission changes even without this 'hack'. (tested on ext4)
A quick test on sshfs seems to confirm that fuse is not covered yet. |
@valoq Thanks - I updated the description. I have included |
#1675 addresses the documentation Remaining issues I noticed so far:
Perhaps the solution is to mix the previous patch that tagged a directory as "updated" with this fsnotify implementation to address all use cases related to timing. |
Hi @valoq do you have steps to reproduce this? And anything helpful like screen recordings? |
Seems to cause issues if there are multiple threads and each one of them is loading the same new file, in which case there is a race condition.
OK so I found that there are race conditions with mass updates (e.g. |
That seems to address all of the mentioned issues, thanks. One more issue I noticed (with and without the threading fix) is that copy actions are very slow now. |
Regarding the slowness, AFAIK there's nothing that can be done about this. When you copy a large file, the data is written in blocks, and Also I'm not sure how why the file size doesn't update for you at the end? For me I tested with the below config, the file size updates at all times during the copy. You'll have to provide the steps for me to reproduce.
|
That was just a mistake on my end, I tested the wrong version. The file size is correctly updated with the latest commit.
One possible solution might be to mark a directory as "updating" during copy operations and skip this line until the copy operation is finished, similar to the approach here. Ignoring this watcher event seems to fix the problem. |
OK this is slightly hacky but I pushed a commit 33f7204 to try and throttle the writes updates. Hopefully this improves the copying time. |
Well it does work I suppose. While it does take significantly less time now, this branch still doubles the execution times for copy operations.
With fsnotify:
If I read correctly, the update time is currently set to 10 milliseconds, changing this to 100 milliseconds may also work, though I didn't notice any less cpu circles used with that change. |
Thanks, I tried 100 milliseconds very briefly as well, the size updates slightly less frequently. But I don't mind changing the time either way. Although I don't think it's worth making this value configurable. |
I don't think an
It's very easy for a user to say this (especially if it their preference), but the fact remains that |
When copying directories with multiple files, the copied directory is now listed with a partial file count. Strangely its appears to be the same wrong number. Probably because of the timing? If I copy the lf source code to lf2 (using cp) the original directory is listed with 44 files and the copy is always listed with 41 until I hit refresh manually.
It got this impression with a lot of the code and I am wondering if the only solid solution is to rewrite large parts of lf with a different approach to file updates. Not that I would find the time to do this either :) So far this patch does not look that complex, especially when considering how many bugs it fixes. |
Setting the refresh time to 100 milliseconds seems to solve the remaining issue and I was not able to recreate the problem with directories with different file numbers or file sizes. |
I tried copying the
I can change the refresh times if you want. But there's two refresh times now, one for reloading directories, and another for updating a file within an existing directory. Which one did you want to change to 100 milliseconds?
Maybe the code looks a bit better now since I rewrote it a bit. But anyway when I mention the complexity, I'm not just talking about the patch itself but all the potential pitfalls involved when using |
Setting this line to 100 milliseconds solved the issue for me Without this change, I also noticed the dircounts of copied directories were sometimes wrong and in some cases several directories inside the copied directories were not listed at all until a manual refresh. Not sure why, but all those issues vanished when the timer in addUpdate is set to 100 |
It's pretty much the same issue as #1667 (comment). With a smaller delay, updates for the same file are sent more frequently, and an older update may overwrite a newer one. I ended up changing both delays to 100 milliseconds, just to keep things consistent. If it doesn't work for you then I'll revert the change for the load delay. |
After f9a51ad writing a file in the listed directory outside of lf causes previews to be redrawn resulting in flickering. In some cases opening a terminal was enough to trigger the redraw, alternatively writing to any file in the filesystem using vim appears to do the same, even when the written file is on another partition entirely. This may be due to new temporary files being created by vim and sometimes by terminals. |
I can reproduce this flickering, but only for the following additional conditions:
But this is a separate bug that already exists, I can reproduce with |
OK I ended up fixing this flicker in #1697 |
That addressed the problem, thank you. |
Hi @valoq, I pushed a new commit b4eb749 to experiment with using a separate dedicated goroutine to handle all the file/directory reloads (also to move as much code into Let me know if it causes any issues, I might reverting the delay back to 100 milliseconds again, or end up reverting the entire commit. |
That seems to fix the race condition as well, thanks. |
There have been no further bugs related to this feature as far as I can tell. (using this branch for two month now) |
Related issues:
This patch uses the
fsnotify
library for watching filesystem updates so that the UI can be updated accordingly. This offers an alternative to polling for updates by using the configurationset period 1
, and should address many of the issues associated with it.The feature can be enabled by configuring
set watch true
. I plan to have it disabled by default as it has not yet been tested thoroughly.List of potential fixes:
set info size:time
) should be updated accordinglyset dircounts true
) should be updated accordinglyImportant
Currently attribute updates (e.g.
chmod
) are being processed, although it is discouraged. Perhaps this can be controlled using an option likewatchchmod
, in which case it is still possible to refresh the UI after performingchmod
, using theload
command:Note
fsnotify
may not work properly for remote/FUSE filesystems. If anyone could help verify this, that would be appreciated.TODO
watch
optionfsnotify