X Tutup
Skip to content

Commit cda406f

Browse files
committed
Better error handling in build script on Windows
`script/build.go` could encounter an "Access is denied" error when the project contains a symlink that could not be followed. This ignores such errors with a warning and allows the build to resume.
1 parent 5984cf2 commit cda406f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

script/build.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package main
2424

2525
import (
26+
"errors"
2627
"fmt"
2728
"io/ioutil"
2829
"os"
@@ -136,8 +137,14 @@ func date() string {
136137

137138
func sourceFilesLaterThan(t time.Time) bool {
138139
foundLater := false
139-
_ = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
140+
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
140141
if err != nil {
142+
// Ignore errors that occur when the project contains a symlink to a filesystem or volume that
143+
// Windows doesn't have access to.
144+
if path != "." && isAccessDenied(err) {
145+
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
146+
return nil
147+
}
141148
return err
142149
}
143150
if foundLater {
@@ -160,9 +167,18 @@ func sourceFilesLaterThan(t time.Time) bool {
160167
}
161168
return nil
162169
})
170+
if err != nil {
171+
panic(err)
172+
}
163173
return foundLater
164174
}
165175

176+
func isAccessDenied(err error) bool {
177+
var pe *os.PathError
178+
// we would use `syscall.ERROR_ACCESS_DENIED` if this script supported build tags
179+
return errors.As(err, &pe) && strings.Contains(pe.Err.Error(), "Access is denied")
180+
}
181+
166182
func rmrf(targets ...string) error {
167183
args := append([]string{"rm", "-rf"}, targets...)
168184
announce(args...)

0 commit comments

Comments
 (0)
X Tutup