feat(fileio): move filename collision checks to Rust
Implement basename extraction, bytewise sorting, collision reporting, and allocation failure handling in the Rust fileio preferences module. Keep programs/fileio.c as the stable ABI shim and preserve non-UTF-8 filenames without lossy conversion. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features cli,compression,decompression - cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets --no-default-features --features cli,compression,decompression - make -B -C tests -j2 test-cli-tests - git diff --cached --check
This commit is contained in:
+2
-29
@@ -306,6 +306,7 @@ static int FIO_shouldDisplayMultipleFileSummary(FIO_ctx_t const* fCtx)
|
||||
|
||||
/* These symbols are implemented by rust/src/fileio_prefs.rs. The declarations
|
||||
* in fileio.h remain the C ABI shims while all actual file I/O stays here. */
|
||||
int FIO_rust_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
||||
|
||||
|
||||
/*-*************************************
|
||||
@@ -678,35 +679,7 @@ static void FIO_initDict(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* co
|
||||
* Checks for and warns if there are any files that would have the same output path
|
||||
*/
|
||||
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles) {
|
||||
const char **filenameTableSorted, *prevElem, *filename;
|
||||
unsigned u;
|
||||
|
||||
filenameTableSorted = (const char**) malloc(sizeof(char*) * nbFiles);
|
||||
if (!filenameTableSorted) {
|
||||
DISPLAYLEVEL(1, "Allocation error during filename collision checking \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (u = 0; u < nbFiles; ++u) {
|
||||
filename = strrchr(filenameTable[u], PATH_SEP);
|
||||
if (filename == NULL) {
|
||||
filenameTableSorted[u] = filenameTable[u];
|
||||
} else {
|
||||
filenameTableSorted[u] = filename+1;
|
||||
}
|
||||
}
|
||||
|
||||
qsort((void*)filenameTableSorted, nbFiles, sizeof(char*), UTIL_compareStr);
|
||||
prevElem = filenameTableSorted[0];
|
||||
for (u = 1; u < nbFiles; ++u) {
|
||||
if (strcmp(prevElem, filenameTableSorted[u]) == 0) {
|
||||
DISPLAYLEVEL(2, "WARNING: Two files have same filename: %s\n", prevElem);
|
||||
}
|
||||
prevElem = filenameTableSorted[u];
|
||||
}
|
||||
|
||||
free((void*)filenameTableSorted);
|
||||
return 0;
|
||||
return FIO_rust_checkFilenameCollisions(filenameTable, nbFiles);
|
||||
}
|
||||
|
||||
char* UTIL_createFilenameFromOutDir(const char* path, const char* outDirName,
|
||||
|
||||
Reference in New Issue
Block a user