-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
pkg/strip: handle read-only input #4450
Conversation
racket/collects/pkg/strip.rkt
Outdated
(define old-mode | ||
(file-or-directory-permissions pth 'bits)) | ||
(define new-mode | ||
(bitwise-ior old-mode user-write-bit)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>.
cca989d
to
c4fd7a1
Compare
I've pushed a revised commit with the fix, plus a commit fixing 55b6cbd the same way. |
@mflatt could you take another look at this? I'm happy to make other changes if needed! |
A package directory supplied to the functions from
pkg/strip
might have had all of its write permission bits unset. Sincecopy-file
preserves the permissions of the source file, we may end up with a read-only file that we want to overwrite (e.g. aninfo.rkt
file). Explicitly settinguser-write-bit
before writing avoids this problem. Conservatively, we restore the original permissions when we are done.