Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of mode bits #250

Merged
merged 1 commit into from Aug 2, 2020
Merged

Improve handling of mode bits #250

merged 1 commit into from Aug 2, 2020

Conversation

anishathalye
Copy link
Contributor

  • "/" should have mode os.ModeDir|0755, not 0000. Among other things, this had resulted in mode.IsDir() returning false for root prior to this patch.
  • Mkdir, MkdirAll, and OpenFile shouldn't be allowed to set permissions that are otherwise illegal through Chmod. This mirrors what Go's os package does: it calls syscallMode(mode), which effectively clears out the same bits that are disallowed by Chmod.
  • MkdirAll should use the given permissions for all intermediate directories that are created, not just for the final directory. Prior to this patch, intermediate directories were created with mode bits 0000. Besides the permission bits being wrong, mode.IsDir() would return false for these directories prior to this patch.

A potentially amusing side note: I was working around these issues in my code by abusing the buggy fs.Chmod(), but that was fixed in #249.

- "/" should have mode `os.ModeDir|0755`, not `0000`. Among other
  things, this had resulted in `mode.IsDir()` returning false for root
  prior to this patch.
- `Mkdir`, `MkdirAll`, and `OpenFile` shouldn't be allowed to set
  permissions that are otherwise illegal through `Chmod`. This mirrors
  what Go's `os` package does: it calls `syscallMode(mode)`, which
  effectively clears out the same bits that are disallowed by `Chmod`.
- `MkdirAll` should use the given permissions for all intermediate
  directories that are created, not just for the final directory. Prior
  to this patch, intermediate directories were created with mode bits
  `0000`. Besides the permission bits being wrong, `mode.IsDir()` would
  return false for these directories prior to this patch.
@CLAassistant
Copy link

CLAassistant commented Jul 15, 2020

CLA assistant check
All committers have signed the CLA.

@JohnStarich
Copy link
Contributor

Nice, this is a great follow-up to the illegal chmod fix. (I'd approve if I could, so poking @Kargakis)

Interesting tidbit, Go itself doesn't support some of those bits for os.Mkdir (for no apparent reason): golang/go#25539

@0xmichalis 0xmichalis merged commit 238028b into spf13:master Aug 2, 2020
@0xmichalis
Copy link
Collaborator

Released in v1.3.3

anishathalye added a commit to anishathalye/periscope that referenced this pull request Aug 2, 2020
Afero 1.3.3 includes a patch (spf13/afero#250)
that fixes some bugs that we were previously working around in
test-related code.
anishathalye added a commit to anishathalye/periscope that referenced this pull request Aug 2, 2020
Afero 1.3.3 includes a patch (spf13/afero#250)
that fixes some bugs that we were previously working around in
test-related code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants