mirror of
https://github.com/golang/go
synced 2024-11-16 23:44:42 -07:00
cmd/gofmt: set backup file permissions on Windows
File.Chmod is supported on Windows since CL 250077, there is no need to skip the call anymore. Updates #18026 Change-Id: Ie03cf016e651b93241f73067614fc4cb341504ef Reviewed-on: https://go-review.googlesource.com/c/go/+/480416 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
3b956dc2d9
commit
012297a862
@ -470,8 +470,6 @@ func fileWeight(path string, info fs.FileInfo) int64 {
|
|||||||
return info.Size()
|
return info.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
const chmodSupported = runtime.GOOS != "windows"
|
|
||||||
|
|
||||||
// backupFile writes data to a new file named filename<number> with permissions perm,
|
// backupFile writes data to a new file named filename<number> with permissions perm,
|
||||||
// with <number randomly chosen such that the file name is unique. backupFile returns
|
// with <number randomly chosen such that the file name is unique. backupFile returns
|
||||||
// the chosen file name.
|
// the chosen file name.
|
||||||
@ -485,13 +483,11 @@ func backupFile(filename string, data []byte, perm fs.FileMode) (string, error)
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
bakname := f.Name()
|
bakname := f.Name()
|
||||||
if chmodSupported {
|
err = f.Chmod(perm)
|
||||||
err = f.Chmod(perm)
|
if err != nil {
|
||||||
if err != nil {
|
f.Close()
|
||||||
f.Close()
|
os.Remove(bakname)
|
||||||
os.Remove(bakname)
|
return bakname, err
|
||||||
return bakname, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write data to backup file
|
// write data to backup file
|
||||||
|
Loading…
Reference in New Issue
Block a user