feat(cli): move regular-file removal to Rust
Route the CLI backend's safe file-removal leaf through a narrow Rust status ABI while preserving C diagnostics, Windows read-only handling, and the existing return convention. Test Plan: cargo test --manifest-path rust/cli/Cargo.toml; 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; make -B -C programs -j2 zstd; make -C tests -j2 test-cli-tests (41 tests); make -B -C programs -j2 zstd-small zstd-frugal.
This commit is contained in:
@@ -35,6 +35,7 @@ RUST_CLI_SOURCES := $(RUST_CLI_MANIFEST) $(RUST_CLI_DIR)/Cargo.lock \
|
||||
$(RUST_CLI_DIR)/src/lib.rs $(RUST_DIR)/src/zstd_cli.rs \
|
||||
$(RUST_DIR)/src/benchzstd.rs \
|
||||
$(RUST_DIR)/src/fileio_prefs.rs \
|
||||
$(RUST_DIR)/src/fileio_backend.rs \
|
||||
$(RUST_DIR)/src/dibio.rs \
|
||||
$(RUST_DIR)/src/util.rs \
|
||||
$(RUST_DIR)/src/zstdcli_trace.rs \
|
||||
|
||||
+13
-13
@@ -305,8 +305,9 @@ static int FIO_shouldDisplayMultipleFileSummary(FIO_ctx_t const* fCtx)
|
||||
#define FIO_LDM_PARAM_NOTSET 9999
|
||||
|
||||
|
||||
/* 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. */
|
||||
/* These policy and filesystem leaves are implemented by the Rust CLI archive.
|
||||
* The declarations in fileio.h remain the C ABI shims while file-I/O
|
||||
* orchestration and diagnostics stay here. */
|
||||
int FIO_rust_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
||||
unsigned FIO_rust_highbit64(unsigned long long v);
|
||||
unsigned long long FIO_rust_getLargestFileSize(const char** inFileNames, unsigned nbFiles);
|
||||
@@ -319,6 +320,7 @@ const char* FIO_rust_determineDstName(const char* srcFileName, const char* outDi
|
||||
int FIO_rust_adjustMemLimitForPatchFromMode(FIO_prefs_t* prefs,
|
||||
unsigned long long dictSize,
|
||||
unsigned long long maxSrcFileSize);
|
||||
int FIO_rust_removeFile(const char* path);
|
||||
#ifdef ZSTD_LZ4COMPRESS
|
||||
int FIO_rust_LZ4_GetBlockSize_FromBlockId(int id);
|
||||
#endif
|
||||
@@ -343,23 +345,21 @@ int FIO_rust_LZ4_GetBlockSize_FromBlockId(int id);
|
||||
* @result : Unlink `fileName`, even if it's read-only */
|
||||
static int FIO_removeFile(const char* path)
|
||||
{
|
||||
stat_t statbuf;
|
||||
if (!UTIL_stat(path, &statbuf)) {
|
||||
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) {
|
||||
DISPLAYLEVEL(2, "zstd: Failed to stat %s while trying to remove it\n", path);
|
||||
return 0;
|
||||
}
|
||||
if (!UTIL_isRegularFileStat(&statbuf)) {
|
||||
if (status == FIO_REMOVE_NON_REGULAR) {
|
||||
DISPLAYLEVEL(2, "zstd: Refusing to remove non-regular file %s\n", path);
|
||||
return 0;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
/* windows doesn't allow remove read-only files,
|
||||
* so try to make it writable first */
|
||||
if (!(statbuf.st_mode & _S_IWRITE)) {
|
||||
UTIL_chmod(path, &statbuf, _S_IWRITE);
|
||||
}
|
||||
#endif
|
||||
return remove(path);
|
||||
return status == FIO_REMOVE_SUCCESS ? 0 : 1;
|
||||
}
|
||||
|
||||
/** FIO_openSrcFile() :
|
||||
|
||||
Reference in New Issue
Block a user