Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and simplify output file permission copying code (shssoichiro#578)
A detailed read to the [Rust documentation for the `fs::Permissions` struct](https://doc.rust-lang.org/stable/std/fs/struct.Permissions.html) 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: - It first read the permissions from the input file metadata. - Then it fetched the output file metadata. - After that, it changed the permissions for that output file metadata. - It then performed a sanity check that the output file had the expected permissions. 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 the `PermissionsExt` 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 on `File` 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 shssoichiro#576, and fix shssoichiro#576.
- Loading branch information