From 2bace2ca0d78c83641cc0691ed7fa3938cea2fec Mon Sep 17 00:00:00 2001 From: hh9527 Date: Tue, 15 Nov 2016 22:06:44 +0800 Subject: [PATCH] Fix: https://github.com/spacejam/rust-rocksdb/issues/96 (#1) * Update ffi_util.rs * Update rocksdb.rs --- src/ffi_util.rs | 3 +-- src/rocksdb.rs | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ffi_util.rs b/src/ffi_util.rs index c979f72..07c3bff 100644 --- a/src/ffi_util.rs +++ b/src/ffi_util.rs @@ -15,11 +15,10 @@ use libc::{self, c_char, c_void}; use std::ffi::CStr; -use std::str; pub fn error_message(ptr: *const c_char) -> String { let cstr = unsafe { CStr::from_ptr(ptr as *const _) }; - let s = str::from_utf8(cstr.to_bytes()).unwrap().to_owned(); + let s = String::from_utf8_lossy(cstr.to_bytes()).into(); unsafe { libc::free(ptr as *mut c_void); } diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 248957c..4e5443f 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -911,10 +911,9 @@ fn errors_do_stuff() { // The DB will still be open when we try to destroy it and the lock should fail. match DB::destroy(&opts, path) { Err(s) => { - assert!(s == - Error::new("IO error: lock _rust_rocksdb_error/LOCK: No \ - locks available" - .to_owned())) + let message = s.to_string(); + assert!(message.find("IO error:").is_some()); + assert!(message.find("_rust_rocksdb_error/LOCK:").is_some()); } Ok(_) => panic!("should fail"), }