Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Added encoding for paths #7

Merged
merged 2 commits into from
Jun 22, 2017
Merged

Added encoding for paths #7

merged 2 commits into from
Jun 22, 2017

Conversation

grbIzl
Copy link

@grbIzl 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 = "*"

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;

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()) {

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

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();

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();

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()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix unwrap

@grbIzl
Copy link
Author

grbIzl commented Jun 16, 2017

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) {

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())?

@rphmeier
Copy link

LGTM, thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants