Skip to content

Commit

Permalink
Review: we don't need canonnicalize anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
darnuria committed Jul 10, 2023
1 parent 653db80 commit 346ea36
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions heed/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ struct EnvEntry {
options: EnvOpenOptions,
}

// Thanks to the mozilla/rkv project
// Workaround the UNC path on Windows, see https://github.com/rust-lang/rust/issues/42869.
// Otherwise, `Env::from_env()` will panic with error_no(123).
#[cfg(not(windows))]
fn canonicalize_path(path: &Path) -> io::Result<PathBuf> {
path.canonicalize()
}

#[cfg(windows)]
fn canonicalize_path(path: &Path) -> io::Result<PathBuf> {
let canonical = path.canonicalize()?;
let url = url::Url::from_file_path(&canonical)
.map_err(|_e| io::Error::new(io::ErrorKind::Other, "URL passing error"))?;
url.to_file_path()
.map_err(|_e| io::Error::new(io::ErrorKind::Other, "path canonicalization error"))
}

#[cfg(windows)]
/// Adding a 'missing' trait from windows OsStrExt
trait OsStrExtLmdb {
Expand Down Expand Up @@ -189,14 +172,14 @@ impl EnvOpenOptions {
pub fn open<P: AsRef<Path>>(&self, path: P) -> Result<Env> {
let mut lock = OPENED_ENV.write().unwrap();

let (path, handle) = match canonicalize_path(path.as_ref()) {
let (path, handle) = match Handle::from_path(&path) {
Err(err) => {
if err.kind() == NotFound && self.flags & (Flag::NoSubDir as u32) != 0 {
let path = path.as_ref();
match path.parent().zip(path.file_name()) {
Some((dir, file_name)) => {
let handle = Handle::from_path(dir)?;
let path = canonicalize_path(dir)?.join(file_name);
let handle = Handle::from_path(&dir)?;
let path = dir.join(file_name);
(path, handle)
}
None => return Err(err.into()),
Expand All @@ -205,10 +188,7 @@ impl EnvOpenOptions {
return Err(err.into());
}
}
Ok(path) => {
let handle = Handle::from_path(&path)?;
(path, handle)
}
Ok(handle) => (path.as_ref().to_path_buf(), handle),
};

match lock.entry(handle) {
Expand Down

0 comments on commit 346ea36

Please sign in to comment.