-
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
Trigger update after copy/move #1638
Conversation
Also added a manual refresh to trigger the update after copy/move without requiring the period option. |
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.
Thanks for your contribution.
The only concern I have is the current change might not be thread-safe, since copyAsync
/moveAsync
are run in separate threads:
if cp { | |
go nav.copyAsync(app, srcs, dstDir) | |
} else { | |
go nav.moveAsync(app, srcs, dstDir) |
On the other hand checkDir
is generally (perhaps exclusively, but I haven't confirmed) called in the main thread.
The problem is that it's hard to prove any issues (as is the case with multithreading in general), and everything worked fine when I tested it myself. Perhaps a safer alternative is to send a command to the event loop using either app.ui.exprChan
or remote
(the latter notifies all instances).
I think it's worth leaving this PR open for a while to see if anyone else has comments.
Also I think you can add #1516 to the Fixes section, I suspect there might be other issues that may be fixed as well. |
I have been thinking about this for a while now and maybe there is something I missed but is there actually any issue with this? We could add a mutex, but I am not familiar enough with go to tell what that entails and if it is worth it if we do not actually solve any theoretical issue with this. Maybe someone with more experience in go/multi-threading can provide some input on this.
Agreed, I will try to add a few more use cases to this manual refresh, like after delete operation. That should cover a few more bugs and provide more chances to catch bugs and side effects. |
For a start, It is important to take thread synchronization seriously in multithreaded programs, even if it is somewhat theoretical and negative effects are rarely observed. For instance there was some issue that was causing
Thanks, I think it will be good if you can compile a list of scenarios that are fixed and add them to the PR description, so anyone else interested in the PR can test the changes. |
It seems like the manual refresh trigger with Since |
I didn't realise that a manual refresh wasn't required either. In this case, I think it should work OK. Thanks for catching that. Thanks, I think it is fine to also update after running a synchronous shell command too. Please ensure these issues are added to the PR description so that they will be automatically closed when the PR is merged.
I did a brief test of the scenario described in #776 (comment) and it worked fine with your changes. This is essentially just an extension of the problem where |
How does it solve the problem yet? |
So this was the test case I was using:
I'm not sure why you mention
|
BTW one other (potentially crazy) idea I had was to use the This will save the need to insert 'update' statements at various points in the code, and should even work if files are changed from an external source (provided |
I misunderstood what the issue #776 was actually about. When you change the number of files in a directory, the file number of the previous directory is not updated either and I was looking for a function where I could add update variable. The number of files in directory a never changes unless I use manual refresh. |
Oh that will be because you set the for _, d := range app.nav.dirs {
d.updated = true
} |
Actually, it seems that the dir size information is already loaded correctly but what is missing is a refresh of the dir cache in the previous pane. checkDir is executed on nav.currDir which also updates the dir size information correctly, so after checkDir the len of currDir in the last image of the above example is already 2 but this information is never updated in the left pane. I did not yet comprehend how the caching works in lf but there is probably an appropriate place in the code that could trigger a simple refresh of the selected directory of the left pane. A full redraw that iterates through all files isn't needed since only the current directory base will change in size (through actions in lf) |
@valoq I'm not sure if you have found it yet, but you should take a look at the What this means is that a |
I opened a separate issue to address the dircounts in the previous pane. #1657 For now I think this MR is ready to merge since there is no longer any threading issue remaining. |
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.
Very well, it may not cover 100% of cases, but it is a small patch and does solve some outstanding problems. I think it is fine to merge this.
This adds the 'updated' member to the dir struct to trigger a manual update of the current directory after copy/move operations (when the period option is used).
Previously the directory information were only updated when the directory mtime was changed, which happens only during file creation but not after the file has finished copying.
Fixes #1417 , Fixes #1226 , Fixes #776
There are probably a few other bugs that can be fixed like this, but I would like some feedback on this approach first.