Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.
Merged
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,20 @@ func Rename(from, to string) error {
// Replace moves a file or directory to a new location and deletes any previous data.
// It is not atomic.
func Replace(from, to string) error {
if err := os.RemoveAll(to); err != nil {
return err
// Remove destionation only if it is a dir.
// Otherwise os.Rename replaces the destination file and is atomic.
{
f, err := os.Stat(to)
if err != nil {
return err
}
if f.IsDir() {
if err := os.RemoveAll(to); err != nil {
return err
}
}
}

if err := os.Rename(from, to); err != nil {
return err
}
Expand Down