summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwqfish <wqfish@calibra.com>2020-01-13 03:23:36 -0800
committerOleksandr Anyshchenko <oleksandr.anyshchenko@xdev.re>2020-01-13 13:23:36 +0200
commita01815d574436a075de8b120d58bae02b32a5d68 (patch)
tree51e34b343b93e791d8f2e7cfe864ccdd416dd403 /src
parent55ed8cbd16392f22c723aede3e2a19b6302ef04b (diff)
Minor cleanup in db.rs (#373)
Reuse the to_cpath function and avoid unnecessary line break.
Diffstat (limited to 'src')
-rw-r--r--src/db.rs43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/db.rs b/src/db.rs
index c3fe596..1500ec2 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -782,17 +782,7 @@ impl DB {
{
let cfs: Vec<_> = cfs.into_iter().collect();
- let path = path.as_ref();
- let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
- Ok(c) => c,
- Err(_) => {
- return Err(Error::new(
- "Failed to convert path to CString \
- when opening DB."
- .to_owned(),
- ));
- }
- };
+ let cpath = to_cpath(&path)?;
if let Err(e) = fs::create_dir_all(&path) {
return Err(Error::new(format!(
@@ -848,9 +838,7 @@ impl DB {
for handle in &cfhandles {
if handle.is_null() {
return Err(Error::new(
- "Received null column family \
- handle from DB."
- .to_owned(),
+ "Received null column family handle from DB.".to_owned(),
));
}
}
@@ -867,7 +855,7 @@ impl DB {
Ok(DB {
inner: db,
cfs: cf_map,
- path: path.to_path_buf(),
+ path: path.as_ref().to_path_buf(),
})
}
@@ -1007,11 +995,8 @@ impl DB {
) -> Result<Option<DBPinnableSlice>, Error> {
if readopts.inner.is_null() {
return Err(Error::new(
- "Unable to create RocksDB read options. \
- This is a fairly trivial call, and its \
- failure may be indicative of a \
- mis-compiled or mis-loaded RocksDB \
- library."
+ "Unable to create RocksDB read options. This is a fairly trivial call, and its \
+ failure may be indicative of a mis-compiled or mis-loaded RocksDB library."
.to_owned(),
));
}
@@ -1050,11 +1035,8 @@ impl DB {
) -> Result<Option<DBPinnableSlice>, Error> {
if readopts.inner.is_null() {
return Err(Error::new(
- "Unable to create RocksDB read options. \
- This is a fairly trivial call, and its \
- failure may be indicative of a \
- mis-compiled or mis-loaded RocksDB \
- library."
+ "Unable to create RocksDB read options. This is a fairly trivial call, and its \
+ failure may be indicative of a mis-compiled or mis-loaded RocksDB library."
.to_owned(),
));
}
@@ -1092,9 +1074,7 @@ impl DB {
Ok(c) => c,
Err(_) => {
return Err(Error::new(
- "Failed to convert path to CString \
- when opening rocksdb"
- .to_owned(),
+ "Failed to convert path to CString when creating cf".to_owned(),
));
}
};
@@ -2005,9 +1985,10 @@ unsafe impl Sync for ReadOptions {}
fn to_cpath<P: AsRef<Path>>(path: P) -> Result<CString, Error> {
match CString::new(path.as_ref().to_string_lossy().as_bytes()) {
Ok(c) => Ok(c),
- Err(_) => Err(Error::new(
- "Failed to convert path to CString when opening DB.".to_owned(),
- )),
+ Err(e) => Err(Error::new(format!(
+ "Failed to convert path to CString: {}",
+ e,
+ ))),
}
}