Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
test_base32:: test_base64:: test_basenc:: test_basename:: \
test_comm:: test_cut:: test_dirname:: test_echo:: \
test_expand:: test_factor:: test_false:: test_fold:: \
test_head:: test_link:: test_ln:: test_nl:: test_numfmt:: \
test_head:: test_link:: test_ln:: test_mktemp:: test_nl:: test_numfmt:: \
test_od:: test_paste:: test_printf:: test_shuf:: test_sum:: \
test_tee:: test_tr:: test_true:: test_truncate:: \
test_unexpand:: test_unlink:: test_wc:: test_yes::
15 changes: 14 additions & 1 deletion src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ impl Options {
} else if matches.get_flag(OPT_T) || matches.contains_id(OPT_TMPDIR) {
// If --tmpdir is given without an argument, or -t is given
// export in TMPDIR
Some(env::temp_dir())
#[cfg(target_os = "wasi")]
// WASI's `std::env::temp_dir()` unconditionally panics
let default_tmp_dir = env::var_os(TMPDIR_ENV_VAR)
.map_or_else(|| PathBuf::from(FALLBACK_TMPDIR), PathBuf::from);
#[cfg(not(target_os = "wasi"))]
let default_tmp_dir = env::temp_dir();
Some(default_tmp_dir)
} else {
None
};
Expand Down Expand Up @@ -629,6 +635,13 @@ fn exec(dir: &Path, prefix: &str, rand: usize, suffix: &str, make_dir: bool) ->
fn get_tmpdir_env_or_default() -> PathBuf {
match env::var_os(TMPDIR_ENV_VAR) {
Some(val) if val.is_empty() => PathBuf::from(FALLBACK_TMPDIR),
// WASI's `std::env::temp_dir()` unconditionally panics,
// so read `TMPDIR` directly.
#[cfg(target_os = "wasi")]
Some(val) => PathBuf::from(val),
#[cfg(target_os = "wasi")]
None => PathBuf::from(FALLBACK_TMPDIR),
#[cfg(not(target_os = "wasi"))]
_ => env::temp_dir(),
}
}
Expand Down
20 changes: 18 additions & 2 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,15 @@ fn test_install_and_strip() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.write("strip", STRIP_PROGRAM);
// Write the strip script and sync to disk to avoid ETXTBSY race on some
// platforms (observed on ARM64 Linux CI runners).
let strip_path = at.plus("strip");
{
use std::io::Write;
let mut f = fs::File::create(&strip_path).unwrap();
f.write_all(STRIP_PROGRAM.as_bytes()).unwrap();
f.sync_all().unwrap();
}
at.set_mode("strip", 0o755);
at.write("source", "file contents");
let path = format!(
Expand Down Expand Up @@ -830,7 +838,15 @@ fn test_install_and_strip_with_program() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.write("strip-program", STRIP_PROGRAM);
// Write the strip script and sync to disk to avoid ETXTBSY race on some
// platforms (observed on ARM64 Linux CI runners).
let strip_path = at.plus("strip-program");
{
use std::io::Write;
let mut f = fs::File::create(&strip_path).unwrap();
f.write_all(STRIP_PROGRAM.as_bytes()).unwrap();
f.sync_all().unwrap();
}
at.set_mode("strip-program", 0o755);
at.write("source", "file contents");

Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fn test_mktemp_mktemp() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_mktemp_t() {
let scene = TestScenario::new(util_name!());

Expand Down Expand Up @@ -399,6 +400,7 @@ fn test_mktemp_suffix() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_tmpdir() {
let scene = TestScenario::new(util_name!());
let dir = tempdir().unwrap();
Expand Down Expand Up @@ -462,6 +464,7 @@ fn test_mktemp_tmpdir() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_empty_tmpdir() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
Expand All @@ -482,6 +485,7 @@ fn test_mktemp_empty_tmpdir() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_tmpdir_one_arg() {
let scene = TestScenario::new(util_name!());

Expand All @@ -495,6 +499,7 @@ fn test_mktemp_tmpdir_one_arg() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_directory_tmpdir() {
let scene = TestScenario::new(util_name!());

Expand Down Expand Up @@ -599,6 +604,11 @@ fn test_respect_template_directory() {

#[cfg(unix)]
#[test]
#[cfg_attr(
wasi_runner,
ignore = "WASI: path_create_directory has no mode parameter and chmod returns ENOSYS, \
so directories can't be created with restricted permissions"
)]
fn test_directory_permissions() {
let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.args(&["-d", "XXX"]).succeeds();
Expand Down Expand Up @@ -869,6 +879,7 @@ fn test_nonexistent_tmpdir_env_var() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_empty_tmpdir_env_var() {
#[cfg(not(any(windows, target_os = "android")))]
{
Expand Down Expand Up @@ -967,11 +978,13 @@ fn test_nonexistent_dir_prefix() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_default_missing_value() {
new_ucmd!().arg("-d").arg("--tmpdir").succeeds();
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_default_issue_4821_t_tmpdir() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
Expand All @@ -987,6 +1000,7 @@ fn test_default_issue_4821_t_tmpdir() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_default_issue_4821_t_tmpdir_p() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
Expand All @@ -1003,6 +1017,7 @@ fn test_default_issue_4821_t_tmpdir_p() {
}

#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_t_ensure_tmpdir_has_higher_priority_than_p() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
Expand Down Expand Up @@ -1183,6 +1198,7 @@ fn test_non_utf8_tmpdir_directory_creation() {

#[test]
#[cfg(unix)]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_mktemp_hidden_file_single_dot() {
let scene = TestScenario::new(util_name!());
let dir = tempdir().unwrap();
Expand Down
Loading