Use same-file only on Windows

This commit is contained in:
Teoh Han Hui 2024-07-14 22:39:42 +08:00
parent e10bdac351
commit 19e3b382b4
No known key found for this signature in database
GPG key ID: D43E2BABAF97DCAE
2 changed files with 6 additions and 3 deletions

View file

@ -18,7 +18,6 @@ deranged = { workspace = true, features = ["serde", "std"] }
directories = { workspace = true, features = [] } directories = { workspace = true, features = [] }
indexmap = { workspace = true, features = ["serde", "std"] } indexmap = { workspace = true, features = ["serde", "std"] }
palette = { workspace = true, features = ["std"] } palette = { workspace = true, features = ["std"] }
same-file = { workspace = true, features = [] }
serde = { workspace = true, features = ["derive", "std"] } serde = { workspace = true, features = ["derive", "std"] }
serde_json = { workspace = true, features = ["std"] } serde_json = { workspace = true, features = ["std"] }
serde_path_to_error = { workspace = true, features = [] } serde_path_to_error = { workspace = true, features = [] }
@ -42,6 +41,7 @@ unicode-normalization = { workspace = true, features = ["std"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
enable-ansi-support = { workspace = true, features = [] } enable-ansi-support = { workspace = true, features = [] }
normpath = { workspace = true, features = [] } normpath = { workspace = true, features = [] }
same-file = { workspace = true, features = [] }
[features] [features]
default = ["autocomplete", "color"] default = ["autocomplete", "color"]

View file

@ -1,6 +1,8 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::io::{ErrorKind, Write}; #[cfg(windows)]
use std::io;
use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::sync::OnceLock; use std::sync::OnceLock;
@ -11,6 +13,7 @@ use anyhow::{anyhow, Context, Result};
use indexmap::IndexMap; use indexmap::IndexMap;
#[cfg(windows)] #[cfg(windows)]
use normpath::PathExt as _; use normpath::PathExt as _;
#[cfg(windows)]
use same_file::is_same_file; use same_file::is_same_file;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
@ -362,7 +365,7 @@ pub fn ensure_git_bash() -> Result<PathBuf> {
match is_same_file(&bash_path, Path::new(&windir).join(r"System32\bash.exe")) { match is_same_file(&bash_path, Path::new(&windir).join(r"System32\bash.exe")) {
Ok(true) => None, Ok(true) => None,
Ok(false) => Some(bash_path), Ok(false) => Some(bash_path),
Err(err) if err.kind() == ErrorKind::NotFound => Some(bash_path), Err(err) if err.kind() == io::ErrorKind::NotFound => Some(bash_path),
Err(err) => { Err(err) => {
return Err(err).context("failed to check if paths refer to the same file"); return Err(err).context("failed to check if paths refer to the same file");
}, },