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

pkg/strip: handle read-only input #4450

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

LiberalArtist
Copy link
Contributor

A package directory supplied to the functions from pkg/strip might have had all of its write permission bits unset. Since copy-file preserves the permissions of the source file, we may end up with a read-only file that we want to overwrite (e.g. an info.rkt file). Explicitly setting user-write-bit before writing avoids this problem. Conservatively, we restore the original permissions when we are done.

(define old-mode
(file-or-directory-permissions pth 'bits))
(define new-mode
(bitwise-ior old-mode user-write-bit))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't work on Windows, where the only thing you can control via file-or-directory-permissions is whether writing is allowed for everyone (i.e., no user vs. group vs. other distinction).

So, (if (eq? (system-type) 'windows) (bitwise-ior user-write-bit group-write-bit other-write-bit) user-write-bit)?

Also, maybe it would be better to try to change permissions only if user-write-bit is not already set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I bet this is also the reason why tests for #4126 failed on Windows. I had seen in the documentation that Windows doesn't have a user/group/other distinction, but I guess I must have thought the non-user bits were just ignored or managed automatically somehow: I didn't realize the user of file-or-directory-permissions was responsible for keeping the bits consistent.

From the linked issues there, it seems like I got it wrong in the same way in 55b6cbd: I'll try to fix that, too.

A package directory supplied to the functions from `pkg/strip` might
have had all of its write permission bits unset. Since `copy-file`
preserves the permissions of the source file, we may end up with a
read-only file that we want to overwrite (e.g. an `info.rkt` file).
Explicitly setting `user-write-bit` before writing avoids this problem.
Conservatively, we only set the permissions when actually needed,
and we restore the original permissions when we are done.
This is a follow-up to 55b6cbd.

On Windows, you can't set just something like `user-write-bit` using
`file-or-directory-permissions`: you have to supply a new mode where
the `user-`, `group-`, and `other-` bits are consistent, because
Windows does not distinguish permissions that way.

See <https://github.com/racket/racket/pull/4450/files#r990709739>.
@LiberalArtist
Copy link
Contributor Author

I've pushed a revised commit with the fix, plus a commit fixing 55b6cbd the same way.

@LiberalArtist
Copy link
Contributor Author

@mflatt could you take another look at this? I'm happy to make other changes if needed!

@mflatt mflatt merged commit 0ddb776 into racket:master Nov 3, 2022
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

2 participants