Skip to content

Commit 4ee8bac

Browse files
ofekmeta-codesync[bot]
authored andcommitted
Improve default permissions for raw artifacts (#144)
Summary: Fixes #107. This changes the fallback mode for single-file artifacts on Unix from owner-executable only to all-users executable. Validation on my Windows machine: ``` ❯ $env.RUSTFLAGS = "-Awarnings" ❯ cargo fmt --check --quiet ❯ cargo test --quiet running 48 tests ................................................ test result: ok. 48 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s running 43 tests ........................................... test result: ok. 43 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.09s ❯ devcontainer exec --workspace-folder . --remote-env $"RUSTFLAGS=($env.RUSTFLAGS)" cargo test --quiet running 49 tests ................................................. test result: ok. 49 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s running 44 tests ............................................ test result: ok. 44 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.07s ❯ devcontainer exec --workspace-folder . cargo clippy --quiet -- $env.RUSTFLAGS ❯ ``` Pull Request resolved: #144 Reviewed By: bigfootjon Differential Revision: D109112264 fbshipit-source-id: b0a8eccc7117be1dc0fdcb62325ce5026d460cf2
1 parent d03c5d4 commit 4ee8bac

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/util/chmodx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::path::Path;
1616

1717
use crate::util::fs_ctx;
1818

19-
const DEFAULT_FILE_PERMISSIONS: u32 = 0o500;
19+
const DEFAULT_FILE_PERMISSIONS: u32 = 0o555;
2020

2121
pub fn chmodx<P: AsRef<Path>>(path: P) -> io::Result<()> {
2222
fn inner(path: &Path) -> io::Result<()> {

tests/dotslash_tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ mod common;
1414

1515
use std::ffi::OsString;
1616
use std::fs;
17+
#[cfg(unix)]
18+
use std::os::unix::fs::PermissionsExt as _;
1719
use std::str;
1820

1921
use tempfile::NamedTempFile;
@@ -907,6 +909,34 @@ fn fetch_simple() -> anyhow::Result<()> {
907909
Ok(())
908910
}
909911

912+
#[cfg(unix)]
913+
#[test]
914+
fn fetch_plain_sets_default_executable_permissions() -> anyhow::Result<()> {
915+
let mut test_env = DotslashTestEnv::try_new()?;
916+
test_env.path_redaction(
917+
"[ARTIFACT_EXE]",
918+
"[DOTSLASH_CACHE_DIR]/[PACK_PLAIN_HTTP_ARCHIVE_CACHE_DIR]/subdir/[PRINT_ARGV_EXECUTABLE]",
919+
);
920+
921+
let assert = test_env
922+
.dotslash_command()
923+
.arg("--")
924+
.arg("fetch")
925+
.arg("tests/fixtures/http__plain__print_argv")
926+
.assert()
927+
.code(0)
928+
.stderr_eq("")
929+
.stdout_eq("[ARTIFACT_EXE]\n");
930+
931+
let artifact = str::from_utf8(&assert.get_output().stdout)?.trim_end();
932+
933+
let metadata = fs::metadata(artifact)?;
934+
assert!(metadata.is_file());
935+
assert_eq!(metadata.permissions().mode() & 0o777, 0o555);
936+
937+
Ok(())
938+
}
939+
910940
//
911941
// "get-extracted-cache-path" Command
912942
//

website/docs/dotslash-file.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ At Meta, we have found compression to be a win, but if for some reason you
475475
prefer to fetch your executable as an uncompressed single file, you can omit the
476476
`"format"` field, but `"path"` is still required.
477477

478+
For single-file artifacts on Unix, if the fetched file has no executable bits,
479+
DotSlash makes the cached file executable with mode `0555` (`r-xr-xr-x`).
480+
478481
## Arg0
479482

480483
There is an optional `arg0` field on an artifact entry. It defaults to

0 commit comments

Comments
 (0)