Skip to content

Commit abec685

Browse files
committed
Get rid of normpath
1 parent e4d6f2d commit abec685

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ regex = { version = "1.5.5", default-features = false, features = ["std", "unico
2323
aho-corasick = "0.7"
2424
tantivy-fst = "0.4.0"
2525
memmap2 = { version = "0.5.3", optional = true }
26-
normpath = "1.0.0"
2726
lz4_flex = { version = "0.10", default-features = false, features = ["checked-decode"], optional = true }
2827
brotli = { version = "3.3.4", optional = true }
2928
zstd = { version = "0.12", optional = true, default-features = false }

src/directory/mmap_directory.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{fmt, result};
99
use common::StableDeref;
1010
use fs2::FileExt;
1111
use memmap2::Mmap;
12-
use normpath::PathExt;
1312
use serde::{Deserialize, Serialize};
1413
use tempfile::TempDir;
1514

@@ -197,9 +196,21 @@ impl MmapDirectory {
197196
directory_path,
198197
)));
199198
}
200-
let canonical_path: PathBuf = directory_path.normalize().map_err(|io_err| {
201-
OpenDirectoryError::wrap_io_error(io_err, PathBuf::from(directory_path))
202-
})?.into_path_buf();
199+
let canonical_path: PathBuf = directory_path.canonicalize().or_else(|io_err| {
200+
let directory_path = directory_path.to_owned();
201+
202+
#[cfg(windows)]
203+
{
204+
// `canonicalize` returns "Incorrect function" (error code 1)
205+
// for virtual drives (network drives, ramdisk, etc.).
206+
if io_err.raw_os_error() == Some(1) && directory_path.exists() {
207+
// Should call `std::path::absolute` when it is stabilised.
208+
return Ok(directory_path);
209+
}
210+
}
211+
212+
Err(OpenDirectoryError::wrap_io_error(io_err, directory_path))
213+
})?;
203214
if !canonical_path.is_dir() {
204215
return Err(OpenDirectoryError::NotADirectory(PathBuf::from(
205216
directory_path,

0 commit comments

Comments
 (0)