Skip to content

Commit

Permalink
cmd/buildlet: handle read-only directories in work area
Browse files Browse the repository at this point in the history
Fixes golang/go#34980

Change-Id: I9d87e2267529212efc370ca6a858452eb829b5bb
Reviewed-on: https://go-review.googlesource.com/c/build/+/201917
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
jclulow authored and bradfitz committed Oct 18, 2019
1 parent aab8504 commit f377c61
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cmd/buildlet/buildlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ var (
// 22: TrimSpace the reverse buildlet's gobuildkey contents
// 23: revdial v2
// 24: removeAllIncludingReadonly
const buildletVersion = 24
// 25: use removeAllIncludingReadonly for all work area cleanup
const buildletVersion = 25

func defaultListenAddr() string {
if runtime.GOOS == "darwin" {
Expand Down Expand Up @@ -193,12 +194,7 @@ func main() {
wdName += "-" + *reverseType
}
dir := filepath.Join(os.TempDir(), wdName)
if err := os.RemoveAll(dir); err != nil { // should be no-op
log.Fatal(err)
}
if err := os.Mkdir(dir, 0755); err != nil {
log.Fatal(err)
}
removeAllAndMkdir(dir)
*workDir = dir
}
}
Expand Down Expand Up @@ -1831,10 +1827,10 @@ func initBaseUnixEnv() {
}
}

// removeAllAndMkdir calls os.RemoveAll and then os.Mkdir on the given
// removeAllAndMkdir calls removeAllIncludingReadonly and then os.Mkdir on the given
// dir, failing the process if either step fails.
func removeAllAndMkdir(dir string) {
if err := os.RemoveAll(dir); err != nil {
if err := removeAllIncludingReadonly(dir); err != nil {
log.Fatal(err)
}
if err := os.Mkdir(dir, 0755); err != nil {
Expand Down

0 comments on commit f377c61

Please sign in to comment.