Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Fix windows panic on os.Rename when target file exists #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions atomicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
)

// File behaves like os.File, but does an atomic rename operation at Close.
Expand Down Expand Up @@ -34,6 +35,11 @@ func (f *File) Close() error {
if err := f.File.Close(); err != nil {
return err
}
if runtime.GOOS == "windows" {
if err := os.Remove(f.path); err != nil {
return err
}
}
if err := os.Rename(f.Name(), f.path); err != nil {
return err
}
Expand Down