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.
This commit is contained in:
parent
5984cf2a82
commit
cda406f495
1 changed files with 17 additions and 1 deletions
|
|
@ -23,6 +23,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -136,8 +137,14 @@ func date() string {
|
|||
|
||||
func sourceFilesLaterThan(t time.Time) bool {
|
||||
foundLater := false
|
||||
_ = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// Ignore errors that occur when the project contains a symlink to a filesystem or volume that
|
||||
// Windows doesn't have access to.
|
||||
if path != "." && isAccessDenied(err) {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if foundLater {
|
||||
|
|
@ -160,9 +167,18 @@ func sourceFilesLaterThan(t time.Time) bool {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return foundLater
|
||||
}
|
||||
|
||||
func isAccessDenied(err error) bool {
|
||||
var pe *os.PathError
|
||||
// we would use `syscall.ERROR_ACCESS_DENIED` if this script supported build tags
|
||||
return errors.As(err, &pe) && strings.Contains(pe.Err.Error(), "Access is denied")
|
||||
}
|
||||
|
||||
func rmrf(targets ...string) error {
|
||||
args := append([]string{"rm", "-rf"}, targets...)
|
||||
announce(args...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue