]> git.lizzy.rs Git - micro.git/blobdiff - internal/buffer/serialize.go
Support csharp-script syntax. (#1425)
[micro.git] / internal / buffer / serialize.go
index 16c4b6bfaabaca45de8e53d0987b9be66742efcf..79c21f6e64a765e9d65ffc823ad7651e42070c19 100644 (file)
@@ -5,6 +5,7 @@ import (
        "errors"
        "io"
        "os"
+       "path/filepath"
        "time"
 
        "golang.org/x/text/encoding"
@@ -30,7 +31,7 @@ func (b *Buffer) Serialize() error {
                return nil
        }
 
-       name := config.ConfigDir + "/buffers/" + util.EscapePath(b.AbsPath)
+       name := filepath.Join(config.ConfigDir, "buffers", util.EscapePath(b.AbsPath))
 
        return overwriteFile(name, encoding.Nop, func(file io.Writer) error {
                err := gob.NewEncoder(file).Encode(SerializedBuffer{
@@ -39,23 +40,24 @@ func (b *Buffer) Serialize() error {
                        b.ModTime,
                })
                return err
-       })
+       }, false)
 }
 
+// Unserialize loads the buffer info from config.ConfigDir/buffers
 func (b *Buffer) Unserialize() error {
        // If either savecursor or saveundo is turned on, we need to load the serialized information
        // from ~/.config/micro/buffers
        if b.Path == "" {
                return nil
        }
-       file, err := os.Open(config.ConfigDir + "/buffers/" + util.EscapePath(b.AbsPath))
+       file, err := os.Open(filepath.Join(config.ConfigDir, "buffers", util.EscapePath(b.AbsPath)))
        defer file.Close()
        if err == nil {
                var buffer SerializedBuffer
                decoder := gob.NewDecoder(file)
                err = decoder.Decode(&buffer)
                if err != nil {
-                       return errors.New(err.Error() + "\nYou may want to remove the files in ~/.config/micro/buffers (these files store the information for the 'saveundo' and 'savecursor' options) if this problem persists.")
+                       return errors.New(err.Error() + "\nYou may want to remove the files in ~/.config/micro/buffers (these files\nstore the information for the 'saveundo' and 'savecursor' options) if\nthis problem persists.\nThis may be caused by upgrading to version 2.0, and removing the 'buffers'\ndirectory will reset the cursor and undo history and solve the problem.")
                }
                if b.Settings["savecursor"].(bool) {
                        b.StartCursor = buffer.Cursor