-
Notifications
You must be signed in to change notification settings - Fork 23
Added encoding for paths #7
Conversation
grbIzl
commented
Jun 15, 2017
- Encoding added. For Windows path local codepage will be used. For posix it will be usual utf-8 string
- Test with non unicode path added
Cargo.toml
Outdated
@@ -26,3 +26,4 @@ path = "test/test.rs" | |||
[dependencies] | |||
libc = "0.2" | |||
rocksdb-sys = { path = "rocksdb-sys", version = "0.3.0" } | |||
local-encoding = "*" |
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.
should pin to specific version
@@ -13,6 +13,7 @@ | |||
// limitations under the License. | |||
// | |||
extern crate rocksdb_sys; | |||
extern crate local_encoding; |
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
src/rocksdb.rs
Outdated
@@ -276,7 +278,8 @@ 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 = Encoding::ANSI.to_bytes(path); | |||
let cpath = match CString::new(encoded_path.unwrap()) { |
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.
unwrap()
is an assertion. Favor expect
which lets you provide a proof for why the assertion will never fail
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.
(our goal is zero panics in Parity code, so all panickers should be backed by a "proof" of why they won't fail)
src/rocksdb.rs
Outdated
@@ -378,7 +381,9 @@ impl DB { | |||
} | |||
|
|||
pub fn destroy(opts: &Options, path: &str) -> Result<(), String> { | |||
let cpath = CString::new(path.as_bytes()).unwrap(); | |||
let encoded_path = Encoding::ANSI.to_bytes(path); | |||
let cpath = CString::new(encoded_path.unwrap()).unwrap(); |
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.
fix unwrap
src/rocksdb.rs
Outdated
@@ -395,7 +400,9 @@ impl DB { | |||
} | |||
|
|||
pub fn repair(opts: &Options, path: &str) -> Result<(), String> { | |||
let cpath = CString::new(path.as_bytes()).unwrap(); | |||
let encoded_path = Encoding::ANSI.to_bytes(path); | |||
let cpath = CString::new(encoded_path.unwrap()).unwrap(); |
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.
fix unwrap
src/rocksdb.rs
Outdated
@@ -518,7 +525,8 @@ impl DB { | |||
name: &str, | |||
opts: &Options) | |||
-> Result<Column, String> { | |||
let cname = match CString::new(name.as_bytes()) { | |||
let encoded_name = Encoding::ANSI.to_bytes(name); | |||
let cname = match CString::new(encoded_name.unwrap()) { |
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.
fix unwrap
Review comments fixed |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
idiomatic rust tip: you can use map_err
and the ?
operator to condense this to
let encoded_path = Encoding::ANSI.to_bytes(path).map_err(|_| "error msg".to_string())?
LGTM, thanks |