I saw that this test is failing at head, with what turns out to be a
dependency on the test environment umask.
This removes the over-strict assertions about permissions from extracted
zips when permissions aren't preserved. I tested locally that it passes
with 022, 002, 077.
Also, some of the comments and variable names seemed to be out of date
for this test, in which the file is not executable, so I changed/removed
them.
cc @MrSubidubi
follows on from #45515
Before:
```
mbp@amorfati ~/s/zed> umask 002
mbp@amorfati ~/s/zed> cargo nextest run -p util archive::tests::test_extract_zip_sets_default_permissions
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.21s
────────────
Nextest run ID de9e0712-0db1-4e4e-8c9f-421bb68ed23c with nextest profile: default
Starting 1 test across 1 binary (71 tests skipped)
FAIL [ 0.003s] util archive::tests::test_extract_zip_sets_default_permissions
stdout ───
running 1 test
test archive::tests::test_extract_zip_sets_default_permissions ... FAILED
failures:
failures:
archive::tests::test_extract_zip_sets_default_permissions
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 71 filtered out; finished in 0.00s
stderr ───
thread 'archive::tests::test_extract_zip_sets_default_permissions' (755934) panicked at crates/util/src/archive.rs:290:13:
assertion `left == right` failed: Expected default set of permissions for unzipped file with no permissions set.
left: 436
right: 420
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
Closes #ISSUE
Release Notes:
- N/A
@@ -266,10 +266,11 @@ mod tests {
smol::block_on(async {
let test_dir = tempfile::tempdir().unwrap();
- let executable_path = test_dir.path().join("my_script");
+ let file_path = test_dir.path().join("my_script");
- // Create an executable file- std::fs::write(&executable_path, "#!/bin/bash\necho 'Hello'").unwrap();
+ std::fs::write(&file_path, "#!/bin/bash\necho 'Hello'").unwrap();
+ // The permissions will be shaped by the umask in the test environment
+ let original_perms = std::fs::metadata(&file_path).unwrap().permissions();
// Create zip
let zip_file = test_dir.path().join("test.zip");
@@ -282,14 +283,20 @@ mod tests {
let reader = read_archive(&zip_file).await;
extract_zip(extract_dir.path(), reader).await.unwrap();
- // Check permissions are preserved
+ // Permissions were not stored, so will be whatever the umask generates
+ // by default for new files. This should match what we saw when we previously wrote
+ // the file.
let extracted_path = extract_dir.path().join("my_script");
assert!(extracted_path.exists());
let extracted_perms = std::fs::metadata(&extracted_path).unwrap().permissions();
assert_eq!(
- extracted_perms.mode() & 0o777,- 0o644,- "Expected default set of permissions for unzipped file with no permissions set."
+ extracted_perms.mode(),
+ original_perms.mode(),
+ "Expected matching Unix file mode for unzipped file without keep_file_permissions"
+ );
+ assert_eq!(
+ extracted_perms, original_perms,
+ "Expected default set of permissions for unzipped file without keep_file_permissions"
);
});
}