Skip to content

fs_util: recover from permission errors when removing buck-out paths#1352

Open
daandemeyer wants to merge 1 commit into
facebook:mainfrom
daandemeyer:push-swmprlnklvnu
Open

fs_util: recover from permission errors when removing buck-out paths#1352
daandemeyer wants to merge 1 commit into
facebook:mainfrom
daandemeyer:push-swmprlnklvnu

Conversation

@daandemeyer

Copy link
Copy Markdown
Contributor

When building OS images with buck2, read-only directories show up in
buck-out because various distributions give their top level directories
and directories in /etc restrictive permissions. Removing such outputs
fails with EACCES, since unlinking a directory entry requires write and
execute permission on the containing directory.

Mirror the existing Windows readonly fallback on Unix:

  • remove_dir_all() now adds owner read/write/execute permission on
    every directory in the tree and retries when it hits a permission
    error. It only ever modifies directories inside the tree being
    removed; in particular it never touches the parent directory of the
    path passed in.

  • A new remove_file_harder() adds owner read/write/execute permission
    on the containing directory and retries. Since that side effects the
    permissions of the (surviving) parent directory, it is kept separate
    from remove_file() and only used where the surrounding tree is being
    deleted anyway: the parallel file removal pass of buck2 clean and
    cleanup_path().

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 3, 2026
@meta-codesync

meta-codesync Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D110600034. (Because this pull request was imported automatically, there will not be any future comments.)

When building OS images with buck2, read-only directories show up in
buck-out because various distributions give their top level directories
and directories in /etc restrictive permissions. Removing such outputs
fails with EACCES, since unlinking a directory entry requires write and
execute permission on the containing directory.

Mirror the existing Windows readonly fallback on Unix:

- remove_dir_all() now adds owner read/write/execute permission on
  every directory in the tree and retries when it hits a permission
  error. It only ever modifies directories inside the tree being
  removed; in particular it never touches the parent directory of the
  path passed in.

- A new remove_file_harder() adds owner read/write/execute permission
  on the containing directory and retries. Since that side effects the
  permissions of the (surviving) parent directory, it is kept separate
  from remove_file() and only used where the surrounding tree is being
  deleted anyway: the parallel file removal pass of buck2 clean and
  cleanup_path().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant