mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 16:48:13 -05:00
fix: really encode windows paths for mdbx this time (#2806)
This commit is contained in:
@@ -8,10 +8,6 @@ use crate::{
|
||||
use byteorder::{ByteOrder, NativeEndian};
|
||||
use libc::c_uint;
|
||||
use mem::size_of;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::{
|
||||
ffi::CString,
|
||||
fmt,
|
||||
@@ -457,9 +453,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
let path = match CString::new(path.as_os_str().as_bytes()) {
|
||||
#[cfg(unix)]
|
||||
fn path_to_bytes<P: AsRef<Path>>(path: P) -> Vec<u8> {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
path.as_ref().as_os_str().as_bytes().to_vec()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn path_to_bytes<P: AsRef<Path>>(path: P) -> Vec<u8> {
|
||||
// On Windows, could use std::os::windows::ffi::OsStrExt to encode_wide(),
|
||||
// but we end up with a Vec<u16> instead of a Vec<u8>, so that doesn't
|
||||
// really help.
|
||||
path.as_ref().to_string_lossy().to_string().into_bytes()
|
||||
}
|
||||
|
||||
let path = match CString::new(path_to_bytes(path)) {
|
||||
Ok(path) => path,
|
||||
Err(..) => return Err(crate::Error::Invalid),
|
||||
Err(_) => return Err(Error::Invalid),
|
||||
};
|
||||
mdbx_result(ffi::mdbx_env_open(
|
||||
env,
|
||||
|
||||
Reference in New Issue
Block a user