From 19e3b382b4bf57dd747b34f426ad52d313ba2949 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Sun, 14 Jul 2024 22:39:42 +0800 Subject: [PATCH] Use same-file only on Windows --- crates/hyfetch/Cargo.toml | 2 +- crates/hyfetch/src/neofetch_util.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/hyfetch/Cargo.toml b/crates/hyfetch/Cargo.toml index 5829463b..1961fac7 100644 --- a/crates/hyfetch/Cargo.toml +++ b/crates/hyfetch/Cargo.toml @@ -18,7 +18,6 @@ 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 = [] } @@ -42,6 +41,7 @@ unicode-normalization = { workspace = true, features = ["std"] } [target.'cfg(windows)'.dependencies] enable-ansi-support = { workspace = true, features = [] } normpath = { workspace = true, features = [] } +same-file = { workspace = true, features = [] } [features] default = ["autocomplete", "color"] diff --git a/crates/hyfetch/src/neofetch_util.rs b/crates/hyfetch/src/neofetch_util.rs index 6bae21fe..999219ff 100644 --- a/crates/hyfetch/src/neofetch_util.rs +++ b/crates/hyfetch/src/neofetch_util.rs @@ -1,6 +1,8 @@ use std::borrow::Cow; 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::process::Command; use std::sync::OnceLock; @@ -11,6 +13,7 @@ use anyhow::{anyhow, Context, Result}; use indexmap::IndexMap; #[cfg(windows)] use normpath::PathExt as _; +#[cfg(windows)] use same_file::is_same_file; use serde::{Deserialize, Serialize}; use tempfile::NamedTempFile; @@ -362,7 +365,7 @@ pub fn ensure_git_bash() -> Result { 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) if err.kind() == io::ErrorKind::NotFound => Some(bash_path), Err(err) => { return Err(err).context("failed to check if paths refer to the same file"); },