Fix git-bash finding in Windows not working properly

This commit is contained in:
SpringMaple 2024-07-14 19:32:06 +08:00 committed by Wilson Kok Weng Ong
parent 198742e15b
commit 6e28482706
5 changed files with 34 additions and 9 deletions

19
Cargo.lock generated
View file

@ -172,6 +172,7 @@ dependencies = [
"normpath",
"palette",
"regex",
"same-file",
"serde",
"serde_json",
"serde_path_to_error",
@ -448,6 +449,15 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.203"
@ -770,6 +780,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View file

@ -23,6 +23,7 @@ indexmap = { version = "2.2.6", default-features = false }
normpath = { version = "1.2.0", default-features = false }
palette = { version = "0.7.6", default-features = false }
regex = { version = "1.10.5", default-features = false }
same-file = { version = "1.0.6", default-features = false }
serde = { version = "1.0.203", default-features = false }
serde_json = { version = "1.0.118", default-features = false }
serde_path_to_error = { version = "0.1.16", default-features = false }

View file

@ -18,6 +18,7 @@ deranged = { workspace = true, features = ["serde", "std"] }
directories = { workspace = true, features = [] }
indexmap = { workspace = true, features = ["serde", "std"] }
palette = { workspace = true, features = ["std"] }
same-file = { workspace = true, features = [] }
serde = { workspace = true, features = ["derive", "std"] }
serde_json = { workspace = true, features = ["std"] }
serde_path_to_error = { workspace = true, features = [] }

View file

@ -41,7 +41,7 @@ _/\_\_ _/_/\_
fn main() -> Result<()> {
#[cfg(windows)]
if let Err(err) = enable_ansi_support::enable_ansi_support() {
debug!(err, "could not enable ANSI escape code support");
debug!(%err, "could not enable ANSI escape code support");
}
let options = options().run();

View file

@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::ffi::OsStr;
use std::io::Write;
use std::io::{ErrorKind, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::OnceLock;
@ -11,6 +11,7 @@ use anyhow::{anyhow, Context, Result};
use indexmap::IndexMap;
#[cfg(windows)]
use normpath::PathExt as _;
use same_file::is_same_file;
use serde::{Deserialize, Serialize};
use tempfile::NamedTempFile;
use tracing::debug;
@ -317,7 +318,7 @@ pub fn neofetch_path() -> Result<Option<PathBuf>> {
let neowofetch_path = if neowofetch_path.is_some() {
neowofetch_path
} else {
let current_exe_path = env::current_exe()
let current_exe_path: PathBuf = env::current_exe()
.and_then(|p| {
#[cfg(not(windows))]
{
@ -358,10 +359,13 @@ pub fn ensure_git_bash() -> Result<PathBuf> {
// See https://github.com/hykilpikonna/hyfetch/issues/233
let windir = env::var_os("windir")
.context("`windir` environment variable is not set or invalid")?;
if bash_path == Path::new(&windir).join(r"System32\bash.exe") {
None
} else {
Some(bash_path)
match is_same_file(&bash_path, Path::new(&windir).join(r"System32\bash.exe")) {
Ok(true) => None,
Ok(false) => Some(bash_path),
Err(err) if err.kind() == ErrorKind::NotFound => Some(bash_path),
Err(err) => {
return Err(err).context("failed to check if paths refer to the same file");
},
}
},
_ => bash_path,
@ -417,7 +421,7 @@ pub fn ensure_git_bash() -> Result<PathBuf> {
let git_bash_path = if git_bash_path.is_some() {
git_bash_path
} else {
let current_exe_path = env::current_exe()
let current_exe_path: PathBuf = env::current_exe()
.and_then(|p| p.normalize().map(|p| p.into()))
.context("failed to get path of current running executable")?;
let bash_path = current_exe_path
@ -738,7 +742,7 @@ fn fastfetch_path() -> Result<Option<PathBuf>> {
};
// Fall back to `fastfetch` in directory of current executable
let current_exe_path = env::current_exe()
let current_exe_path: PathBuf = env::current_exe()
.and_then(|p| {
#[cfg(not(windows))]
{