Add executable permissions to directories when attempting to clean up build directory
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 378
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 74
Description
## Problem
If a build does something silly like `chmod 0444 ./subdir`, attempts to clean up the build directory [will fail with messages like](https://buildkite.com/julialang/julia-master/builds/39322#01916b11-6bff-4a23-a6e8-dac68df78347/48-113):
```
# Removing /Users/julia/buildkite-agent/build/julia-master
🚨 Error: Failed to remove "/Users/julia/buildkite-agent/build/julia-master" (fstatat /Users/julia/buildkite-agent/build/julia-master/subdir/Manifest.toml: permission denied)
```
Then, subsequent git checkouts will fail (because that build directory is not empty) and the cleanup process will fail all over again. In our case, this happened due to a misconfigured `find . -name \*.jl -exec chmod 0444 {} \;` which found directories with names that ended in `.jl` instead of source code files like we intended. Unfortunately, this then required manual intervention on the build agent machines to clear out those bad permissions to allow the build to successfully go through.
## Potential solution
I propose that when buildkite is attempting to clear out the build directory, that it should add execute (and write) permissions to all subdirectories, e.g. the equivalent of:
```
find . -type d -exec chmod u+wx {} \;
```
This will allow normal directory removal code to then process the repository. I don't think there's any valid usecase for allowing user code to create things that cannot be deleted like this, as it badly breaks the ability of buildkite to deal with the build directory.
Contributor guide
Assessment
This issue has not been assessed yet.