Skip to content
Myr

Fix directory-existence check on Windows

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This fixes a bug on Windows where `fd` could not be used on ram disks and encrypted folders. closes #752

authored by David Peter · committed by David Peter · parent 6e44828 · Browse files · 4 files+23 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+23 added−8 removed

  • other:+23 added−8 removed

4 files+23 added−8 removed

modified:src/filesystem.rs+6 added-4 removed
5 unmodified lines
6#[cfg(any(unix, target_os = "redox"))]7use std::os::unix::fs::{FileTypeExt, PermissionsExt};8use std::path::{Path, PathBuf};910use normpath::PathExt;1112use crate::walk;1314pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {15 if path.is_absolute() {
18 unmodified lines
3435 Ok(path_buf)36}3736// Path::is_dir() is not guaranteed to be intuitively correct for "." and ".."37// See: https://github.com/rust-lang/rust/issues/4530238pub fn is_dir(path: &Path) -> bool {39 path.is_dir() && (path.file_name().is_some() || path.canonicalize().is_ok())38pub fn is_existing_directory(path: &Path) -> bool {39 // Note: we do not use `.exists()` here, as `.` always exists, even if40 // the CWD has been deleted.41 path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())42}4344#[cfg(any(unix, target_os = "redox"))]45pub fn is_executable(md: &fs::Metadata) -> bool {
103 unmodified lines
modified:src/main.rs+4 added-4 removed
53 unmodified lines
5455 // Set the current working directory of the process56 if let Some(base_directory) = matches.value_of_os("base-directory") {57 let base_directory = Path::new(base_directory);58 if !filesystem::is_dir(base_directory) {58 if !filesystem::is_existing_directory(base_directory) {59 return Err(anyhow!(60 "The '--base-directory' path '{}' is not a directory.",61 base_directory.to_string_lossy()62 ));
6 unmodified lines
69 })?;70 }7172 let current_directory = Path::new(".");73 if !filesystem::is_dir(current_directory) {73 if !filesystem::is_existing_directory(current_directory) {74 return Err(anyhow!(75 "Could not retrieve current directory (has it been deleted?)."76 ));77 }
16 unmodified lines
94 let mut search_paths = if let Some(paths) = passed_arguments {95 let mut directories = vec![];96 for path in paths {97 let path_buffer = PathBuf::from(path);98 if filesystem::is_dir(&path_buffer) {98 if filesystem::is_existing_directory(&path_buffer) {99 directories.push(path_buffer);100 } else {101 print_error(format!(102 "Search path '{}' is not a directory.",
26 unmodified lines
129130 // Detect if the user accidentally supplied a path instead of a search pattern131 if !matches.is_present("full-path")132 && pattern.contains(std::path::MAIN_SEPARATOR)133 && filesystem::is_dir(Path::new(pattern))133 && Path::new(pattern).is_dir()134 {135 return Err(anyhow!(136 "The search pattern '{pattern}' contains a path-separation character ('{sep}') \137 and will not lead to any search results.\n\n\
353 unmodified lines
modified:Cargo.lock+12 added
1# This file is automatically @generated by Cargo.2# It is not intended for manual editing.3version = 345[[package]]6name = "aho-corasick"7version = "0.7.18"8source = "registry+https://github.com/rust-lang/crates.io-index"
158 unmodified lines
167 "jemallocator",168 "lazy_static",169 "libc",170 "lscolors",171 "normpath",172 "num_cpus",173 "regex",174 "regex-syntax",175 "tempdir",
157 unmodified lines
333 "libc",334]335336[[package]]337name = "normpath"338version = "0.3.0"339source = "registry+https://github.com/rust-lang/crates.io-index"340checksum = "27e6e8f70e9fbbe3752d330d769e3424f24b9458ce266df93a3b456902fd696a"341dependencies = [342 "winapi",343]344345[[package]]346name = "num_cpus"347version = "1.13.0"348source = "registry+https://github.com/rust-lang/crates.io-index"349checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
222 unmodified lines
modified:Cargo.toml+1 added