Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/micro/micro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"testing"

"github.com/go-errors/errors"
Expand Down Expand Up @@ -157,8 +158,10 @@ func openFile(file string) {

func findBuffer(file string) *buffer.Buffer {
var buf *buffer.Buffer
file, _ = filepath.EvalSymlinks(file)
file, _ = filepath.Abs(file)
for _, b := range buffer.OpenBuffers {
if b.Path == file {
if b.AbsPath == file {
buf = b
}
}
Expand Down
21 changes: 15 additions & 6 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,16 @@ func NewBufferFromString(text, path string, btype BufType) *Buffer {
// Places the cursor at startcursor. If startcursor is -1, -1 places the
// cursor at an autodetected location (based on savecursor or :LINE:COL)
func NewBuffer(r io.Reader, size int64, path string, btype BufType, cmd Command) *Buffer {
absPath, err := filepath.Abs(path)
if err != nil {
absPath = path
var err error
absPath := path
if btype == BTDefault && path != "" {
// Ignore the returned error, since the checks are already performed in
// NewBufferFromFileWithCommand()
path, _ = filepath.EvalSymlinks(path)
absPath, err = filepath.Abs(path)
if err != nil {
absPath = path
}
}

b := new(Buffer)
Expand Down Expand Up @@ -524,10 +531,12 @@ func (b *Buffer) Close() {
// Fini should be called when a buffer is closed and performs
// some cleanup
func (b *Buffer) Fini() {
if !b.Modified() {
b.Serialize()
if !b.Shared() {
if !b.Modified() {
b.Serialize()
}
b.CancelBackup()
}
b.CancelBackup()

if b.Type == BTStdout {
fmt.Fprint(util.Stdout, string(b.Bytes()))
Expand Down
2 changes: 2 additions & 0 deletions internal/buffer/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ func (b *Buffer) saveToFile(filename string, withSudo bool, autoSave bool) error
return errors.New("Error: " + filename + " is not a regular file and cannot be saved")
}

// Ignore the returned error, since the checks are already performed above
filename, _ = filepath.EvalSymlinks(filename)
absFilename, err := filepath.Abs(filename)
if err != nil {
return err
Expand Down