Fix and simplify output file permission copying code #578
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A detailed read to the Rust documentation for the
fs::Permissions
struct and a little digging into its implementation in the standard library have shown that this code didn't work as expected in any platform, and was a bit weird to begin with:Barring the fact that the sanity check in step 4 is not needed, the overall approach is wrong because setting the permissions in a file metadata struct does not actually persist those changes anywere; it's just an in-memory change only, so these operations were useless. The Rust documentation explicitly mentions that the
set_readonly
method "does not modify the files attributes" [sic], but it's easy to miss that warning and not realize that it also applies to the methods offered by thePermissionsExt
trait. The code only appeared to work because in most cases the default permissions for new files happen to match the input file permissions, so the sanity check passed.To fix this, use the
set_permissions
method onFile
to actually set the output file permissions to be the same as the input file permissions, which is both much simpler and robust.These changes were tested in the context of issue #576, and fix #576.