This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
forked from rust-rocksdb/rust-rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 23
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ use self::libc::size_t; | |
use rocksdb_ffi::{self, DBCFHandle, error_message}; | ||
use rocksdb_options::{Options, WriteOptions}; | ||
|
||
use local_encoding::{Encoding, Encoder}; | ||
|
||
pub struct DB { | ||
inner: rocksdb_ffi::DBInstance, | ||
cfs: BTreeMap<String, DBCFHandle>, | ||
|
@@ -276,7 +278,16 @@ impl DB { | |
if cfs.len() != cf_opts.len() { | ||
return Err(format!("Mismatching number of CF options")); | ||
} | ||
let cpath = match CString::new(path.as_bytes()) { | ||
let encoded_path = match Encoding::ANSI.to_bytes(path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idiomatic rust tip: you can use |
||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to encode path to codepage when opening \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cpath = match CString::new(encoded_path) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to convert path to CString when opening \ | ||
|
@@ -378,7 +389,24 @@ impl DB { | |
} | ||
|
||
pub fn destroy(opts: &Options, path: &str) -> Result<(), String> { | ||
let cpath = CString::new(path.as_bytes()).unwrap(); | ||
let encoded_path = match Encoding::ANSI.to_bytes(path) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to encode path to codepage when destroying \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cpath = match CString::new(encoded_path) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to convert path to CString when destroying \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cpath_ptr = cpath.as_ptr(); | ||
|
||
let mut err: *const i8 = 0 as *const i8; | ||
|
@@ -395,7 +423,24 @@ impl DB { | |
} | ||
|
||
pub fn repair(opts: &Options, path: &str) -> Result<(), String> { | ||
let cpath = CString::new(path.as_bytes()).unwrap(); | ||
let encoded_path = match Encoding::ANSI.to_bytes(path) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to encode path to codepage when repairing \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cpath = match CString::new(encoded_path) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to convert path to CString when repairing \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cpath_ptr = cpath.as_ptr(); | ||
|
||
let mut err: *const i8 = 0 as *const i8; | ||
|
@@ -518,7 +563,16 @@ impl DB { | |
name: &str, | ||
opts: &Options) | ||
-> Result<Column, String> { | ||
let cname = match CString::new(name.as_bytes()) { | ||
let encoded_name = match Encoding::ANSI.to_bytes(name) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to encode path to codepage when opening \ | ||
rocksdb" | ||
.to_string()) | ||
} | ||
}; | ||
|
||
let cname = match CString::new(encoded_name) { | ||
Ok(c) => c, | ||
Err(_) => { | ||
return Err("Failed to convert path to CString when opening \ | ||
|
@@ -1024,6 +1078,18 @@ fn iterator_test() { | |
assert!(DB::destroy(&opts, path).is_ok()); | ||
} | ||
|
||
#[test] | ||
fn non_unicode_path_test() { | ||
let path = "путь_не_юникод/_rust_rocksdb_unicode_test"; | ||
{ | ||
let db = DB::open_default(path).unwrap(); | ||
assert!(db.put(b"my key", b"my value").is_ok()); | ||
assert!(db.delete(b"my key").is_ok()); | ||
} | ||
let opts = Options::new(); | ||
assert!(DB::destroy(&opts, path).is_ok()); | ||
} | ||
|
||
#[test] | ||
fn snapshot_test() { | ||
let path = "_rust_rocksdb_snapshottest"; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: newline between links and pub exports