feat(cli): move multi-file output policy to Rust
Port the scalar decision matrix for multi-input concatenation behind the CLI Rust ABI. C retains warnings, preference mutation, fatal diagnostics, and confirmation prompts; Rust now classifies protection, remove-file disabling, quiet abort, and confirmation paths with focused coverage. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml fileio_prefs::tests::multi_files_concat - cargo clippy --manifest-path rust/cli/Cargo.toml - cargo clippy --manifest-path rust/cli/Cargo.toml --benches - cargo clippy --manifest-path rust/cli/Cargo.toml --tests - cargo +nightly fmt --manifest-path rust/Cargo.toml --all - make -B -C programs -j2 zstd - make -C tests -j2 test-cli-tests
This commit is contained in:
@@ -22,6 +22,12 @@ const FIO_LDM_PARAM_NOTSET: c_int = 9999;
|
||||
const FIO_PATCH_MEM_LIMIT_SUCCESS: c_int = 0;
|
||||
const FIO_PATCH_MEM_LIMIT_UNKNOWN_SIZE: c_int = 1;
|
||||
const FIO_PATCH_MEM_LIMIT_TOO_LARGE: c_int = 2;
|
||||
const FIO_MULTI_FILES_ACTION_PROCEED: c_int = 0;
|
||||
const FIO_MULTI_FILES_ACTION_FATAL_STDOUT_REMOVE: c_int = 1;
|
||||
const FIO_MULTI_FILES_ACTION_FATAL_TEST_REMOVE: c_int = 2;
|
||||
const FIO_MULTI_FILES_ACTION_DISABLE_REMOVE: c_int = 3;
|
||||
const FIO_MULTI_FILES_ACTION_QUIET_ABORT: c_int = 4;
|
||||
const FIO_MULTI_FILES_ACTION_CONFIRM: c_int = 5;
|
||||
const UTIL_FILESIZE_UNKNOWN: u64 = u64::MAX;
|
||||
const ZSTD_WINDOWLOG_MAX: u32 = if size_of::<usize>() == 4 { 30 } else { 31 };
|
||||
const ZSTD_BTLAZY2: c_int = 6;
|
||||
@@ -603,6 +609,67 @@ pub extern "C" fn FIO_rust_cycleLog(hash_log: c_uint, strategy: c_int) -> c_uint
|
||||
cycle_log(hash_log, strategy)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[inline]
|
||||
fn multi_files_concat_action(
|
||||
nb_files_total: c_int,
|
||||
has_stdout_output: c_int,
|
||||
test_mode: c_int,
|
||||
has_output_file: c_int,
|
||||
remove_src_file: c_int,
|
||||
overwrite: c_int,
|
||||
display_level: c_int,
|
||||
display_level_cutoff: c_int,
|
||||
) -> c_int {
|
||||
if has_stdout_output != 0 && remove_src_file != 0 {
|
||||
return FIO_MULTI_FILES_ACTION_FATAL_STDOUT_REMOVE;
|
||||
}
|
||||
if test_mode != 0 && remove_src_file != 0 {
|
||||
return FIO_MULTI_FILES_ACTION_FATAL_TEST_REMOVE;
|
||||
}
|
||||
if test_mode != 0 || nb_files_total <= 1 || has_output_file == 0 {
|
||||
return FIO_MULTI_FILES_ACTION_PROCEED;
|
||||
}
|
||||
if remove_src_file != 0 {
|
||||
return FIO_MULTI_FILES_ACTION_DISABLE_REMOVE;
|
||||
}
|
||||
if has_stdout_output != 0 || overwrite != 0 {
|
||||
return FIO_MULTI_FILES_ACTION_PROCEED;
|
||||
}
|
||||
if display_level <= display_level_cutoff {
|
||||
FIO_MULTI_FILES_ACTION_QUIET_ABORT
|
||||
} else {
|
||||
FIO_MULTI_FILES_ACTION_CONFIRM
|
||||
}
|
||||
}
|
||||
|
||||
/// Select the warning/prompt action for multiple inputs sharing one output.
|
||||
///
|
||||
/// C retains the user-facing diagnostics, preference mutation, and prompt;
|
||||
/// Rust only evaluates the scalar policy and returns the action enum.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn FIO_rust_multiFilesConcatAction(
|
||||
nb_files_total: c_int,
|
||||
has_stdout_output: c_int,
|
||||
test_mode: c_int,
|
||||
has_output_file: c_int,
|
||||
remove_src_file: c_int,
|
||||
overwrite: c_int,
|
||||
display_level: c_int,
|
||||
display_level_cutoff: c_int,
|
||||
) -> c_int {
|
||||
multi_files_concat_action(
|
||||
nb_files_total,
|
||||
has_stdout_output,
|
||||
test_mode,
|
||||
has_output_file,
|
||||
remove_src_file,
|
||||
overwrite,
|
||||
display_level,
|
||||
display_level_cutoff,
|
||||
)
|
||||
}
|
||||
|
||||
fn largest_file_size<I>(sizes: I) -> u64
|
||||
where
|
||||
I: IntoIterator<Item = u64>,
|
||||
@@ -1112,6 +1179,72 @@ mod tests {
|
||||
assert_eq!(FIO_rust_cycleLog(20, ZSTD_BTLAZY2 + 3), 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_files_concat_policy_protects_stdout_and_test_mode_removal() {
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 1, 0, 1, 1, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_FATAL_STDOUT_REMOVE
|
||||
);
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 1, 1, 1, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_FATAL_TEST_REMOVE
|
||||
);
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 1, 1, 0, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_PROCEED
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_files_concat_policy_keeps_nonconcatenating_paths_quiet() {
|
||||
for (nb_files, has_output_file) in [(1, 1), (3, 0)] {
|
||||
assert_eq!(
|
||||
multi_files_concat_action(nb_files, 0, 0, has_output_file, 0, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_PROCEED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_files_concat_policy_disables_remove_before_other_decisions() {
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 0, 1, 1, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_DISABLE_REMOVE
|
||||
);
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 0, 1, 0, 0, 1, 1),
|
||||
FIO_MULTI_FILES_ACTION_QUIET_ABORT
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_files_concat_policy_allows_stdout_and_overwrite() {
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 1, 0, 1, 0, 0, 0, 1),
|
||||
FIO_MULTI_FILES_ACTION_PROCEED
|
||||
);
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 0, 1, 0, 1, 0, 1),
|
||||
FIO_MULTI_FILES_ACTION_PROCEED
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_files_concat_policy_uses_quiet_and_confirmation_boundaries() {
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 0, 1, 0, 0, 1, 1),
|
||||
FIO_MULTI_FILES_ACTION_QUIET_ABORT
|
||||
);
|
||||
assert_eq!(
|
||||
multi_files_concat_action(3, 0, 0, 1, 0, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_CONFIRM
|
||||
);
|
||||
assert_eq!(
|
||||
FIO_rust_multiFilesConcatAction(3, 0, 0, 1, 0, 0, 2, 1),
|
||||
FIO_MULTI_FILES_ACTION_CONFIRM
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_shims_preserve_fields_and_c_layout() {
|
||||
let input_word = size_of::<*const c_void>();
|
||||
|
||||
Reference in New Issue
Block a user