]> git.lizzy.rs Git - micro.git/commitdiff
Never backup closed buffers
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 4 Sep 2020 17:36:23 +0000 (13:36 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 4 Sep 2020 17:36:23 +0000 (13:36 -0400)
internal/buffer/backup.go
internal/buffer/buffer.go

index f23627ab805b15fb57f269704eeba936e93fb613..419b4a9bda46843be4d124cd3a46a51652637aa7 100644 (file)
@@ -5,6 +5,7 @@ import (
        "io"
        "os"
        "path/filepath"
+       "sync/atomic"
        "time"
 
        "github.com/zyedidia/micro/v2/internal/config"
@@ -36,7 +37,10 @@ func backupThread() {
 
                for len(backupRequestChan) > 0 {
                        b := <-backupRequestChan
-                       b.Backup()
+                       bfini := atomic.LoadInt32(&(b.fini)) != 0
+                       if !bfini {
+                               b.Backup()
+                       }
                }
        }
 }
index dfbd36446f33407f80e3115da1d31b009b57d30b..ae66be4b753dad07e4b0c2cf6cfedb147c4309f7 100644 (file)
@@ -14,6 +14,7 @@ import (
        "strconv"
        "strings"
        "sync"
+       "sync/atomic"
        "time"
 
        luar "layeh.com/gopher-luar"
@@ -184,6 +185,7 @@ type Buffer struct {
        *EventHandler
        *SharedBuffer
 
+       fini        int32
        cursors     []*Cursor
        curCursor   int
        StartCursor Loc
@@ -396,6 +398,8 @@ func (b *Buffer) Fini() {
        if b.Type == BTStdout {
                fmt.Fprint(util.Stdout, string(b.Bytes()))
        }
+
+       atomic.StoreInt32(&(b.fini), int32(1))
 }
 
 // GetName returns the name that should be displayed in the statusline