-
Notifications
You must be signed in to change notification settings - Fork 327
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
Error in second lf instance when using "paste; clear" to cut/paste files #1470
Comments
I can reproduce this too, about half the time. After some investigation, I found that this is because of a timing issue where instance 2 is reading from Consider the code below, which is called when cutting and pasting files:
The error message comes from here:
The first line of I guess it's possible to fix this by just returning if the file is blank, for example: diff --git a/app.go b/app.go
index 4131633..3efc436 100644
--- a/app.go
+++ b/app.go
@@ -115,20 +115,23 @@ func loadFiles() (list []string, cp bool, err error) {
s := bufio.NewScanner(files)
s.Scan()
switch s.Text() {
case "copy":
cp = true
case "move":
cp = false
+ case "": // the file could be empty if another lf instance is writing to it
+ cp = false
+ return
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
list = append(list, s.Text())
}
if s.Err() != nil { Alternative;ly, I think it might be worth revisiting the discussion in #1011, which I believe is where the idea of using |
@joelim-work The discussion in #1011 is about changing the builtin default behavior to |
@karabaja4 I spent some more time investigating this, it looks like the truncation happens immediately when diff --git a/app.go b/app.go
index 4131633..0c40d6c 100644
--- a/app.go
+++ b/app.go
@@ -157,20 +157,21 @@ func saveFiles(list []string, cp bool) error {
if cp {
fmt.Fprintln(files, "copy")
} else {
fmt.Fprintln(files, "move")
}
for _, f := range list {
fmt.Fprintln(files, f)
}
+ files.Sync()
return nil
}
func (app *app) readHistory() error {
f, err := os.Open(gHistoryPath)
if os.IsNotExist(err) {
return nil
}
if err != nil {
return fmt.Errorf("opening history file: %s", err) I am thinking of submitting this as an actual PR if there are no issues, so it would be nice if you could test it too, just to be sure. I think this patch is cleaner than the one I proposed earlier about ignoring empty files. @gokcehan Regarding the default behavior of |
@joelim-work It works correctly with that patch, or at least I'm unable reproduce the problem anymore described in the original post. Thanks! |
Thanks, I have submitted a PR: #1480 |
Steps to reproduce:
The second instance will show the following error:
The file is still moved successfully.
The text was updated successfully, but these errors were encountered: