Skip to content

Commit

Permalink
Stop CreateWithMode from attempting to set the mode on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Dec 7, 2018
1 parent 6625ffc commit 4621ad1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions xio/fs/safe/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"

"github.com/richardwilkes/toolbox/xio"
)
Expand Down Expand Up @@ -37,12 +38,14 @@ func CreateWithMode(filename string, mode os.FileMode) (*File, error) {
if err != nil {
return nil, err
}
if err = f.Chmod(mode); err != nil {
xio.CloseIgnoringErrors(f)
if rerr := os.Remove(f.Name()); rerr != nil && err == nil {
err = rerr // Won't happen, but here to quiet the linter
if runtime.GOOS != "windows" { // Windows doesn't support changing the mode
if err = f.Chmod(mode); err != nil {
xio.CloseIgnoringErrors(f)
if rerr := os.Remove(f.Name()); rerr != nil && err == nil {
err = rerr // Won't happen, but here to quiet the linter
}
return nil, err
}
return nil, err
}
return &File{
File: f,
Expand Down

0 comments on commit 4621ad1

Please sign in to comment.