refactor(cli): move pass-through selection policy to Rust
Move automatic decompression pass-through selection into a pure Rust scalar policy while preserving explicit preference values, stdout probing, overwrite semantics, assertions, diagnostics, and all C-owned file/resource callbacks. The C fileio boundary now supplies only the policy inputs before constructing the existing callback projection. Test Plan: ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings; cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings; cargo test --manifest-path rust/cli/Cargo.toml --all-targets (188 passed); cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check; make -j1; ./tests/rustLibSmoke; make -j1 -C tests test (all shell tests, large streaming tests, native tester, fuzzer phases, and zstream tester passed).
This commit is contained in:
@@ -64,6 +64,31 @@ pub const FIO_RUST_DECOMPRESS_DIAGNOSTIC_LZMA_UNSUPPORTED: c_int = 4;
|
||||
pub const FIO_RUST_DECOMPRESS_DIAGNOSTIC_LZ4_UNSUPPORTED: c_int = 5;
|
||||
pub const FIO_RUST_DECOMPRESS_DIAGNOSTIC_UNSUPPORTED_FORMAT: c_int = 6;
|
||||
|
||||
/// Resolves the legacy automatic pass-through mode without touching the
|
||||
/// destination name or any C-owned file state. Explicit values are returned
|
||||
/// unchanged so the C assertion keeps its original validation behavior.
|
||||
#[inline]
|
||||
fn decompress_pass_through_policy(
|
||||
pass_through: c_int,
|
||||
overwrite: c_int,
|
||||
destination_is_stdout: c_int,
|
||||
) -> c_int {
|
||||
if pass_through == -1 {
|
||||
(overwrite != 0 && destination_is_stdout != 0) as c_int
|
||||
} else {
|
||||
pass_through
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn FIO_rust_decompressPassThroughPolicy(
|
||||
pass_through: c_int,
|
||||
overwrite: c_int,
|
||||
destination_is_stdout: c_int,
|
||||
) -> c_int {
|
||||
decompress_pass_through_policy(pass_through, overwrite, destination_is_stdout)
|
||||
}
|
||||
|
||||
/// Maps decompression results to the diagnostics that the C CLI displays.
|
||||
/// Statuses without a legacy diagnostic deliberately map to `NONE`, retaining
|
||||
/// the previous C callback's silent default case.
|
||||
@@ -5299,6 +5324,25 @@ impl PoolInner {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn decompression_pass_through_policy_preserves_explicit_and_default_modes() {
|
||||
for pass_through in [0, 1] {
|
||||
assert_eq!(
|
||||
decompress_pass_through_policy(pass_through, 0, 0),
|
||||
pass_through
|
||||
);
|
||||
assert_eq!(
|
||||
decompress_pass_through_policy(pass_through, 1, 1),
|
||||
pass_through
|
||||
);
|
||||
}
|
||||
|
||||
assert_eq!(decompress_pass_through_policy(-1, 0, 0), 0);
|
||||
assert_eq!(decompress_pass_through_policy(-1, 0, 1), 0);
|
||||
assert_eq!(decompress_pass_through_policy(-1, 1, 0), 0);
|
||||
assert_eq!(decompress_pass_through_policy(-1, 1, 1), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decompression_status_diagnostic_preserves_cli_mapping() {
|
||||
for (status, diagnostic) in [
|
||||
|
||||
Reference in New Issue
Block a user