Fix deletion of non-executable but readable directories

Deleting a non-executable directory is tricky; the opendir/readdir syscalls on the
directory itself will succeed (and return the full list of directory entries), but
any filesystem operation on the entries (stat, open, unlink, etc.) will fail with
EACCES.

In Java, the behavior of FileSystem method calls for listing and deleting directory
entries depends on whether or not the particular implementation stats the entries or
not. In any case, deletion of entries requires the directory permissions to be
changed.

The trivial fix would be to set directory executable (and readable and writable)
before calling deleteTree() or deleteTreesBelow() - but that would carry an
unacceptable cost in the number of system calls to address what should be a rare
situation.

Instead, in UnixFileSystem's jni code, we can check if errno == EACCES after the
first filesystem operation on a directory entry, and if so, change permissions.

In the generic Java FileSystem implementation, we can't see errno, so we have to
* introduce a new deleteStrict() method which (unlike delete()) throws instead of
  returning false when attempting to delete an entry that the FileSystem cannot
  stat; and
* fix permissions and retry recursive deletion when deleteStrict() throws.

Fixes #11010 (also see discussion in PR #11045).

RELNOTES: Bazel can now recursively delete non-executable but readable directories.
PiperOrigin-RevId: 309970825
3 files changed
tree: 55ac92e938249b5f61e19caf6c2147b98cf4b6ba
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status