]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gofmt: set backup file permissions on Windows
authorqmuntal <quimmuntal@gmail.com>
Thu, 30 Mar 2023 08:28:32 +0000 (10:28 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Fri, 31 Mar 2023 22:38:04 +0000 (22:38 +0000)
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>
src/cmd/gofmt/gofmt.go

index e464d64c98bac3724b07c6b5c7e57159592371d9..00c8cbdb939d00a62280e31425a7e17715729e67 100644 (file)
@@ -470,8 +470,6 @@ func fileWeight(path string, info fs.FileInfo) int64 {
        return info.Size()
 }
 
-const chmodSupported = runtime.GOOS != "windows"
-
 // 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
 // the chosen file name.
@@ -485,13 +483,11 @@ func backupFile(filename string, data []byte, perm fs.FileMode) (string, error)
                return "", err
        }
        bakname := f.Name()
-       if chmodSupported {
-               err = f.Chmod(perm)
-               if err != nil {
-                       f.Close()
-                       os.Remove(bakname)
-                       return bakname, err
-               }
+       err = f.Chmod(perm)
+       if err != nil {
+               f.Close()
+               os.Remove(bakname)
+               return bakname, err
        }
 
        // write data to backup file