From dfbf55f833f307623292f55adf219299a79e442b Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Mon, 19 Jan 2015 16:31:38 -0500 Subject: [PATCH] add db repair function --- src/rocksdb.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/rocksdb.rs b/src/rocksdb.rs index e1658fc..a3e4b69 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -75,10 +75,7 @@ impl RocksDB { let ospath = Path::new(path); if !ospath.exists() { - match fs::mkdir_recursive(&ospath, io::USER_DIR) { - Err(e) => return Err(e.desc), - Ok(_) => (), - } + return Err("path does not exist"); } let err = 0 as *mut i8; @@ -92,6 +89,27 @@ impl RocksDB { } } + pub fn repair(opts: RocksDBOptions, path: &str) -> Result<(), &str> { + unsafe { + let cpath = CString::from_slice(path.as_bytes()); + let cpath_ptr = cpath.as_ptr(); + + let ospath = Path::new(path); + if !ospath.exists() { + return Err("path does not exist"); + } + + let err = 0 as *mut i8; + let result = rocksdb_ffi::rocksdb_repair_db( + opts.inner, cpath_ptr, err); + if !err.is_null() { + let cs = from_c_str(err as *const i8); + return Err(cs); + } + Ok(()) + } + } + pub fn create_snapshot(self) -> RocksDBSnapshot { unsafe { rocksdb_ffi::rocksdb_create_snapshot(self.inner) @@ -128,7 +146,6 @@ impl RocksDB { } } - pub fn get<'a>(&self, key: &[u8]) -> RocksDBResult<'a, RocksDBVector, &str> { unsafe {