refactor(cli): move file-removal policy to Rust

Keep FIO_removeFile responsible for the filesystem operation, exact diagnostics, and C return wrapper, but route its status classification through a Rust policy bridge. Unknown statuses are explicitly treated as failed removal. ABI value assertions and focused mapping tests preserve the C contract.

Test Plan: Not run in this atomic commit; the capped serial Rust, native, smoke, and original test-suite verification follows.
This commit is contained in:
2026-07-21 07:55:18 +02:00
parent b89acb1fb5
commit 78c4118a67
2 changed files with 99 additions and 9 deletions
+34 -9
View File
@@ -435,6 +435,31 @@ void FIO_rust_freeDict(int dictBufferType,
size_t* bufferSize,
void** dictHandle);
int FIO_rust_removeFile(const char* path);
enum {
FIO_REMOVE_SUCCESS = 0,
FIO_REMOVE_STAT_FAILED = 1,
FIO_REMOVE_NON_REGULAR = 2,
FIO_REMOVE_FAILED = 3
};
enum {
FIO_RUST_REMOVE_FILE_ACTION_SUCCESS = 0,
FIO_RUST_REMOVE_FILE_ACTION_STAT_FAILED = 1,
FIO_RUST_REMOVE_FILE_ACTION_NON_REGULAR = 2,
FIO_RUST_REMOVE_FILE_ACTION_FAILED = 3,
FIO_RUST_REMOVE_FILE_ACTION_INVALID = 4
};
typedef char FIO_rust_remove_file_status_values[
(FIO_REMOVE_SUCCESS == 0
&& FIO_REMOVE_STAT_FAILED == 1
&& FIO_REMOVE_NON_REGULAR == 2
&& FIO_REMOVE_FAILED == 3) ? 1 : -1];
typedef char FIO_rust_remove_file_action_values[
(FIO_RUST_REMOVE_FILE_ACTION_SUCCESS == 0
&& FIO_RUST_REMOVE_FILE_ACTION_STAT_FAILED == 1
&& FIO_RUST_REMOVE_FILE_ACTION_NON_REGULAR == 2
&& FIO_RUST_REMOVE_FILE_ACTION_FAILED == 3
&& FIO_RUST_REMOVE_FILE_ACTION_INVALID == 4) ? 1 : -1];
int FIO_rust_removeFileAction(int status);
int FIO_rust_passThrough(ReadPoolCtx_t* readCtx, WritePoolCtx_t* writeCtx);
enum {
FIO_RUST_ZSTD_FRAME_OK = 0,
@@ -647,21 +672,21 @@ int FIO_LZ4_GetBlockSize_FromBlockId(int id);
* @result : Unlink `fileName`, even if it's read-only */
static int FIO_removeFile(const char* path)
{
enum {
FIO_REMOVE_SUCCESS = 0,
FIO_REMOVE_STAT_FAILED = 1,
FIO_REMOVE_NON_REGULAR = 2,
};
int const status = FIO_rust_removeFile(path);
if (status == FIO_REMOVE_STAT_FAILED) {
switch (FIO_rust_removeFileAction(status)) {
case FIO_RUST_REMOVE_FILE_ACTION_STAT_FAILED:
DISPLAYLEVEL(2, "zstd: Failed to stat %s while trying to remove it\n", path);
return 0;
}
if (status == FIO_REMOVE_NON_REGULAR) {
case FIO_RUST_REMOVE_FILE_ACTION_NON_REGULAR:
DISPLAYLEVEL(2, "zstd: Refusing to remove non-regular file %s\n", path);
return 0;
case FIO_RUST_REMOVE_FILE_ACTION_SUCCESS:
return 0;
case FIO_RUST_REMOVE_FILE_ACTION_FAILED:
case FIO_RUST_REMOVE_FILE_ACTION_INVALID:
default:
return 1;
}
return status == FIO_REMOVE_SUCCESS ? 0 : 1;
}
/** FIO_openSrcFile() :