refactor(fileio): move list-file ordering to Rust
Move the single-file --list status gates, diagnostic-versus-metadata ordering, and aggregate projection into Rust. C retains file opening and frame analysis, the private fileInfo_t layout, exact diagnostics, and row formatting behind explicit callbacks, so the user-visible behavior remains unchanged while the policy boundary is auditable. Test Plan: - git diff --cached --check - worker format, check, clippy, and serial C compilation (passed); focused Rust tests compiled but the standalone link hit the pre-existing C bridge-symbol gap
This commit is contained in:
+78
-42
@@ -4781,8 +4781,8 @@ typedef enum {
|
||||
info_truncated_input=4
|
||||
} InfoError;
|
||||
|
||||
/* Rust owns the scalar --list file-status action policy. C keeps the exact
|
||||
* diagnostics, metadata formatting, file I/O, and private fileInfo_t layout. */
|
||||
/* Rust owns the --list file policy/order. C keeps the exact diagnostics,
|
||||
* metadata formatting, file I/O, and private fileInfo_t layout. */
|
||||
enum {
|
||||
FIO_RUST_LIST_FILE_ACTION_SUCCESS = 0,
|
||||
FIO_RUST_LIST_FILE_ACTION_FRAME_ERROR = 1,
|
||||
@@ -4795,7 +4795,7 @@ int FIO_rust_listFileStatusAction(int status);
|
||||
|
||||
/* Keep the private fileInfo_t layout in C. This projection contains only the
|
||||
* fields needed by the --list total row and crosses the Rust policy boundary
|
||||
* after FIO_listFile has finished its C-owned open/parse/display work. */
|
||||
* after the C-owned file-info and display callbacks have run. */
|
||||
typedef struct {
|
||||
U64 decompressedSize;
|
||||
U64 compressedSize;
|
||||
@@ -4806,6 +4806,35 @@ typedef struct {
|
||||
U32 nbFiles;
|
||||
} FIO_listFileInfoProjection_t;
|
||||
|
||||
typedef int (*FIO_listFileGetInfoFn)(void* opaque, const char* fileName,
|
||||
fileInfo_t* info);
|
||||
typedef void (*FIO_listFileDisplayStatusFn)(void* opaque, int action,
|
||||
const char* fileName,
|
||||
int displayLevel);
|
||||
typedef void (*FIO_listFileDisplayInfoFn)(void* opaque, const char* fileName,
|
||||
const fileInfo_t* info,
|
||||
int displayLevel);
|
||||
|
||||
/* This callback state is a deliberate repr(C) bridge: filesystem access,
|
||||
* frame analysis, exact diagnostics, and row formatting stay in C while Rust
|
||||
* owns the per-file policy/order around them. */
|
||||
typedef struct {
|
||||
void* opaque;
|
||||
FIO_listFileGetInfoFn getInfo;
|
||||
FIO_listFileDisplayStatusFn displayStatus;
|
||||
FIO_listFileDisplayInfoFn displayInfo;
|
||||
} FIO_listFileCallbacks_t;
|
||||
|
||||
typedef char FIO_rust_list_file_callbacks_get_info_offset[
|
||||
(offsetof(FIO_listFileCallbacks_t, getInfo) == sizeof(void*)) ? 1 : -1];
|
||||
typedef char FIO_rust_list_file_callbacks_status_offset[
|
||||
(offsetof(FIO_listFileCallbacks_t, displayStatus)
|
||||
== sizeof(void*) + sizeof(FIO_listFileGetInfoFn)) ? 1 : -1];
|
||||
typedef char FIO_rust_list_file_callbacks_info_offset[
|
||||
(offsetof(FIO_listFileCallbacks_t, displayInfo)
|
||||
== sizeof(void*) + sizeof(FIO_listFileGetInfoFn)
|
||||
+ sizeof(FIO_listFileDisplayStatusFn)) ? 1 : -1];
|
||||
|
||||
typedef struct {
|
||||
void* opaque;
|
||||
int (*isStdin)(void* opaque, const char* fileName);
|
||||
@@ -4818,6 +4847,9 @@ typedef struct {
|
||||
const FIO_listFileInfoProjection_t* total);
|
||||
} FIO_listMultipleFilesCallbacks_t;
|
||||
|
||||
int FIO_rust_listFile(const char* inputName, int displayLevel,
|
||||
FIO_listFileInfoProjection_t* output,
|
||||
const FIO_listFileCallbacks_t* callbacks);
|
||||
int FIO_rust_listMultipleFiles(unsigned numFiles, const char** filenameTable,
|
||||
int displayLevel,
|
||||
const FIO_listMultipleFilesCallbacks_t* callbacks);
|
||||
@@ -4987,49 +5019,48 @@ displayInfo(const char* inFileName, const fileInfo_t* info, int displayLevel)
|
||||
}
|
||||
|
||||
static int
|
||||
FIO_listFile(const char* inFileName, int displayLevel,
|
||||
FIO_listFileInfoProjection_t* output)
|
||||
FIO_listFileGetInfo(void* opaque, const char* inFileName, fileInfo_t* info)
|
||||
{
|
||||
fileInfo_t info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
{ InfoError const error = getFileInfo(&info, inFileName);
|
||||
int const action = FIO_rust_listFileStatusAction((int)error);
|
||||
switch (action) {
|
||||
case FIO_RUST_LIST_FILE_ACTION_FRAME_ERROR:
|
||||
/* display error, but provide output */
|
||||
DISPLAYLEVEL(1, "Error while parsing \"%s\" \n", inFileName);
|
||||
break;
|
||||
case FIO_RUST_LIST_FILE_ACTION_NOT_ZSTD:
|
||||
DISPLAYOUT("File \"%s\" not compressed by zstd \n", inFileName);
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
return 1;
|
||||
case FIO_RUST_LIST_FILE_ACTION_FILE_ERROR:
|
||||
/* error occurred while opening the file */
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
return 1;
|
||||
case FIO_RUST_LIST_FILE_ACTION_TRUNCATED_INPUT:
|
||||
DISPLAYOUT("File \"%s\" is truncated \n", inFileName);
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
return 1;
|
||||
case FIO_RUST_LIST_FILE_ACTION_SUCCESS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)opaque;
|
||||
return (int)getFileInfo(info, inFileName);
|
||||
}
|
||||
|
||||
displayInfo(inFileName, &info, displayLevel);
|
||||
output->decompressedSize = info.decompressedSize;
|
||||
output->compressedSize = info.compressedSize;
|
||||
output->numActualFrames = info.numActualFrames;
|
||||
output->numSkippableFrames = info.numSkippableFrames;
|
||||
output->decompUnavailable = info.decompUnavailable;
|
||||
output->usesCheck = info.usesCheck;
|
||||
output->nbFiles = info.nbFiles;
|
||||
assert(action == FIO_RUST_LIST_FILE_ACTION_SUCCESS
|
||||
|| action == FIO_RUST_LIST_FILE_ACTION_FRAME_ERROR);
|
||||
return (int)error;
|
||||
static void
|
||||
FIO_listFileDisplayStatus(void* opaque, int action,
|
||||
const char* inFileName, int displayLevel)
|
||||
{
|
||||
(void)opaque;
|
||||
switch (action) {
|
||||
case FIO_RUST_LIST_FILE_ACTION_FRAME_ERROR:
|
||||
/* display error, but provide output */
|
||||
DISPLAYLEVEL(1, "Error while parsing \"%s\" \n", inFileName);
|
||||
break;
|
||||
case FIO_RUST_LIST_FILE_ACTION_NOT_ZSTD:
|
||||
DISPLAYOUT("File \"%s\" not compressed by zstd \n", inFileName);
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
break;
|
||||
case FIO_RUST_LIST_FILE_ACTION_FILE_ERROR:
|
||||
/* error occurred while opening the file */
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
break;
|
||||
case FIO_RUST_LIST_FILE_ACTION_TRUNCATED_INPUT:
|
||||
DISPLAYOUT("File \"%s\" is truncated \n", inFileName);
|
||||
if (displayLevel > 2) DISPLAYOUT("\n");
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
FIO_listFileDisplayInfo(void* opaque, const char* inFileName,
|
||||
const fileInfo_t* info, int displayLevel)
|
||||
{
|
||||
(void)opaque;
|
||||
displayInfo(inFileName, info, displayLevel);
|
||||
}
|
||||
|
||||
/* Rust owns this stateless --list input-name predicate. */
|
||||
int FIO_listFileIsStdin(void* opaque, const char* fileName);
|
||||
|
||||
@@ -5062,9 +5093,14 @@ static int
|
||||
FIO_listFileCallback(void* opaque, const char* fileName, int displayLevel,
|
||||
FIO_listFileInfoProjection_t* info)
|
||||
{
|
||||
FIO_listFileCallbacks_t callbacks;
|
||||
(void)opaque;
|
||||
memset(info, 0, sizeof(*info));
|
||||
return FIO_listFile(fileName, displayLevel, info);
|
||||
callbacks.opaque = NULL;
|
||||
callbacks.getInfo = FIO_listFileGetInfo;
|
||||
callbacks.displayStatus = FIO_listFileDisplayStatus;
|
||||
callbacks.displayInfo = FIO_listFileDisplayInfo;
|
||||
return FIO_rust_listFile(fileName, displayLevel, info, &callbacks);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user