diff --git a/librocksdb_sys/crocksdb/c.cc b/librocksdb_sys/crocksdb/c.cc index e1c78168c..3931afd6c 100644 --- a/librocksdb_sys/crocksdb/c.cc +++ b/librocksdb_sys/crocksdb/c.cc @@ -2877,6 +2877,14 @@ void crocksdb_env_join_all_threads(crocksdb_env_t* env) { env->rep->WaitForJoin(); } +void crocksdb_env_file_exists(crocksdb_env_t* env, const char* path, char** errptr) { + SaveError(errptr, env->rep->FileExists(path)); +} + +void crocksdb_env_delete_file(crocksdb_env_t* env, const char* path, char** errptr) { + SaveError(errptr, env->rep->DeleteFile(path)); +} + void crocksdb_env_destroy(crocksdb_env_t* env) { if (!env->is_default) delete env->rep; delete env; diff --git a/librocksdb_sys/crocksdb/crocksdb/c.h b/librocksdb_sys/crocksdb/crocksdb/c.h index dff4ff32d..0f46dfb20 100644 --- a/librocksdb_sys/crocksdb/crocksdb/c.h +++ b/librocksdb_sys/crocksdb/crocksdb/c.h @@ -1194,6 +1194,10 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_env_set_high_priority_background_threads(crocksdb_env_t* env, int n); extern C_ROCKSDB_LIBRARY_API void crocksdb_env_join_all_threads( crocksdb_env_t* env); +extern C_ROCKSDB_LIBRARY_API void crocksdb_env_file_exists( + crocksdb_env_t* env, const char* path, char** errptr); +extern C_ROCKSDB_LIBRARY_API void crocksdb_env_delete_file( + crocksdb_env_t* env, const char* path, char** errptr); extern C_ROCKSDB_LIBRARY_API void crocksdb_env_destroy(crocksdb_env_t*); extern C_ROCKSDB_LIBRARY_API crocksdb_envoptions_t* crocksdb_envoptions_create(); diff --git a/librocksdb_sys/src/lib.rs b/librocksdb_sys/src/lib.rs index 83c064b12..dac76dceb 100644 --- a/librocksdb_sys/src/lib.rs +++ b/librocksdb_sys/src/lib.rs @@ -1065,6 +1065,8 @@ extern "C" { // Env pub fn crocksdb_create_default_env() -> *mut DBEnv; pub fn crocksdb_create_mem_env() -> *mut DBEnv; + pub fn crocksdb_env_file_exists(env: *mut DBEnv, path: *const c_char, err: *mut *mut c_char); + pub fn crocksdb_env_delete_file(env: *mut DBEnv, path: *const c_char, err: *mut *mut c_char); pub fn crocksdb_env_destroy(env: *mut DBEnv); // EnvOptions diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 4497fac0b..a986c88e1 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -1892,6 +1892,22 @@ impl Env { Ok(SequentialFile::new(file)) } } + + pub fn file_exists(&self, path: &str) -> Result<(), String> { + unsafe { + let file_path = CString::new(path).unwrap(); + ffi_try!(crocksdb_env_file_exists(self.inner, file_path.as_ptr())); + Ok(()) + } + } + + pub fn delete_file(&self, path: &str) -> Result<(), String> { + unsafe { + let file_path = CString::new(path).unwrap(); + ffi_try!(crocksdb_env_delete_file(self.inner, file_path.as_ptr())); + Ok(()) + } + } } impl Drop for Env { diff --git a/tests/test_ingest_external_file.rs b/tests/test_ingest_external_file.rs index 285ca9106..57eb9d69d 100644 --- a/tests/test_ingest_external_file.rs +++ b/tests/test_ingest_external_file.rs @@ -427,4 +427,8 @@ fn test_mem_sst_file_writer() { (b"k3", Some(b"v3")), ], ); + + assert!(env.file_exists(mem_sst_str).is_ok()); + assert!(env.delete_file(mem_sst_str).is_ok()); + assert!(env.file_exists(mem_sst_str).is_err()); }