fix: stricter casefold matching (#3470)

This commit is contained in:
三咲雅 misaki masa 2025-12-28 16:05:06 +08:00 committed by GitHub
parent 77d36ff5a5
commit faf33e1b03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 113 additions and 74 deletions

56
Cargo.lock generated
View file

@ -913,9 +913,9 @@ dependencies = [
[[package]]
name = "crypto-common"
version = "0.2.0-rc.7"
version = "0.2.0-rc.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c52310bbf9ce8ad2f05bf8a9b0aa3585532884c31b4f191badfe7d7c7ed127"
checksum = "e6165b8029cdc3e765b74d3548f85999ee799d5124877ce45c2c85ca78e4d4aa"
dependencies = [
"hybrid-array",
]
@ -1154,13 +1154,13 @@ dependencies = [
[[package]]
name = "digest"
version = "0.11.0-rc.4"
version = "0.11.0-rc.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea390c940e465846d64775e55e3115d5dc934acb953de6f6e6360bc232fe2bf7"
checksum = "ebf9423bafb058e4142194330c52273c343f8a5beb7176d052f0e73b17dd35b9"
dependencies = [
"block-buffer 0.11.0",
"const-oid 0.10.1",
"crypto-common 0.2.0-rc.7",
"crypto-common 0.2.0-rc.8",
]
[[package]]
@ -1934,7 +1934,7 @@ checksum = "fe44f2bbd99fcb302e246e2d6bcf51aeda346d02a365f80296a07a8c711b6da6"
dependencies = [
"argon2",
"bcrypt-pbkdf",
"digest 0.11.0-rc.4",
"digest 0.11.0-rc.5",
"ecdsa",
"ed25519-dalek",
"hex",
@ -1950,7 +1950,7 @@ dependencies = [
"sha1 0.11.0-rc.3",
"sha2 0.10.9",
"signature 2.2.0",
"signature 3.0.0-rc.5",
"signature 3.0.0-rc.6",
"ssh-cipher",
"ssh-encoding",
"subtle",
@ -1994,9 +1994,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.16"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee5b5339afb4c41626dde77b7a611bd4f2c202b897852b4bcf5d03eddc61010"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "jobserver"
@ -2160,9 +2160,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "libredox"
version = "0.1.11"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df15f6eac291ed1cf25865b1ee60399f57e7c227e7f51bdbd4c5270396a9ed50"
checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616"
dependencies = [
"bitflags 2.10.0",
"libc",
@ -3064,9 +3064,9 @@ dependencies = [
[[package]]
name = "portable-atomic"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f59e70c4aef1e55797c2e8fd94a4f2a973fc972cfde0e0b05f683667b0cd39dd"
checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950"
[[package]]
name = "powerfmt"
@ -3116,9 +3116,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.103"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0"
dependencies = [
"unicode-ident",
]
@ -3557,12 +3557,12 @@ dependencies = [
"const-oid 0.10.1",
"crypto-bigint 0.7.0-rc.10",
"crypto-primes",
"digest 0.11.0-rc.4",
"digest 0.11.0-rc.5",
"pkcs1",
"pkcs8 0.11.0-rc.8",
"rand_core 0.10.0-rc-3",
"sha2 0.11.0-rc.3",
"signature 3.0.0-rc.5",
"signature 3.0.0-rc.6",
"spki 0.8.0-rc.4",
"subtle",
"zeroize",
@ -3709,9 +3709,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "ryu"
version = "1.0.21"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62049b2877bf12821e8f9ad256ee38fdc31db7387ec2d3b3f403024de2034aea"
checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
[[package]]
name = "safe_arch"
@ -3819,9 +3819,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.147"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6af14725505314343e673e9ecb7cd7e8a36aa9791eb936235a3567cc31447ae4"
checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da"
dependencies = [
"itoa",
"memchr",
@ -3868,7 +3868,7 @@ checksum = "aa1ae819b9870cadc959a052363de870944a1646932d274a4e270f64bf79e5ef"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.11.0-rc.4",
"digest 0.11.0-rc.5",
]
[[package]]
@ -3890,7 +3890,7 @@ checksum = "19d43dc0354d88b791216bb5c1bfbb60c0814460cc653ae0ebd71f286d0bd927"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.11.0-rc.4",
"digest 0.11.0-rc.5",
]
[[package]]
@ -3963,11 +3963,11 @@ dependencies = [
[[package]]
name = "signature"
version = "3.0.0-rc.5"
version = "3.0.0-rc.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0251c9d6468f4ba853b6352b190fb7c1e405087779917c238445eb03993826"
checksum = "597a96996ccff7dfa16f052bd995b4cecc72af22c35138738dc029f0ead6608d"
dependencies = [
"digest 0.11.0-rc.4",
"digest 0.11.0-rc.5",
"rand_core 0.10.0-rc-3",
]
@ -5888,9 +5888,9 @@ dependencies = [
[[package]]
name = "zmij"
version = "0.1.10"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4af59da1029247450b54ba43e0b62c8e376582464bbe5504dd525fe521e7e8fd"
checksum = "e6d6085d62852e35540689d1f97ad663e3971fc19cf5eceab364d62c646ea167"
[[package]]
name = "zune-core"

View file

@ -53,7 +53,7 @@ regex = "1.12.2"
russh = { version = "0.56.0", default-features = false, features = [ "ring", "rsa" ] }
scopeguard = "1.2.0"
serde = { version = "1.0.228", features = [ "derive" ] }
serde_json = "1.0.147"
serde_json = "1.0.148"
syntect = { version = "5.3.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
thiserror = "2.0.17"
tokio = { version = "1.48.0", features = [ "full" ] }

View file

@ -19,7 +19,7 @@ impl Actor for Reveal {
// Cd to the parent directory
act!(mgr:cd, cx, (parent, opt.source))?;
// Try to hover on the child file
// Try to hover over the child file
let tab = cx.tab_mut();
render!(tab.current.hover(child));
@ -30,7 +30,7 @@ impl Actor for Reveal {
tab.current.update_pub(tab.id, op);
}
// Now, we can safely hover on the target
// Now, we can safely hover over the target
act!(mgr:hover, cx, Some(child.into()))?;
act!(mgr:peek, cx)?;

View file

@ -43,9 +43,9 @@ keymap = [
{ on = "L", run = "forward", desc = "Forward to next directory" },
# Toggle
{ on = "<Space>", run = [ "toggle", "arrow next" ], desc = "Toggle the current selection state" },
{ on = "<C-a>", run = "toggle_all --state=on", desc = "Select all files" },
{ on = "<C-r>", run = "toggle_all", desc = "Invert selection of all files" },
{ on = "<Space>", run = [ "toggle", "arrow 1" ], desc = "Toggle the current selection state" },
{ on = "<C-a>", run = "toggle_all --state=on", desc = "Select all files" },
{ on = "<C-r>", run = "toggle_all", desc = "Invert selection of all files" },
# Visual mode
{ on = "v", run = "visual_mode", desc = "Enter visual mode (selection mode)" },

View file

@ -2,7 +2,7 @@ use anyhow::{Result, bail};
use serde::Deserialize;
use yazi_codegen::DeserializeOver2;
use yazi_fs::{CWD, SortBy};
use yazi_shared::{SyncCell, url::{UrlBuf, UrlLike}};
use yazi_shared::{SyncCell, url::UrlLike};
use super::{MgrRatio, MouseEvents};
@ -32,8 +32,8 @@ impl Mgr {
return None;
}
let home = UrlBuf::from(dirs::home_dir().unwrap_or_default());
let cwd = if let Ok(p) = CWD.load().try_strip_prefix(&home) {
let home = dirs::home_dir().unwrap_or_default();
let cwd = if let Ok(p) = CWD.load().try_strip_prefix(home) {
format!("~{}{}", std::path::MAIN_SEPARATOR, p.display())
} else {
format!("{}", CWD.load().display())

View file

@ -47,6 +47,7 @@ fn casefold_impl(path: PathBuf) -> io::Result<PathBuf> {
}
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(irrefutable_let_patterns)]
fn casefold_impl(path: PathBuf) -> io::Result<PathBuf> {
use std::{ffi::{CString, OsStr, OsString}, fs::File, os::{fd::{AsRawFd, FromRawFd}, unix::{ffi::{OsStrExt, OsStringExt}, fs::MetadataExt}}};
@ -54,7 +55,7 @@ fn casefold_impl(path: PathBuf) -> io::Result<PathBuf> {
let cstr = CString::new(path.into_os_string().into_vec())?;
let path = Path::new(OsStr::from_bytes(cstr.as_bytes()));
let Some(parent) = path.parent() else {
let Some((parent, name)) = path.parent().zip(path.file_name()) else {
return Ok(PathBuf::from(OsString::from_vec(cstr.into_bytes())));
};
@ -64,34 +65,49 @@ fn casefold_impl(path: PathBuf) -> io::Result<PathBuf> {
};
// Fast path: if the `/proc/self/fd/N` matches
let oss = path.as_os_str();
if let Ok(p) = std::fs::read_link(format!("/proc/self/fd/{}", file.as_raw_fd()))
&& let Some(b) = p.as_os_str().as_bytes().get(..oss.len())
&& b.eq_ignore_ascii_case(oss.as_bytes())
&& let path = path.as_os_str()
&& let Some(b) = p.as_os_str().as_bytes().get(..path.len())
&& b.eq_ignore_ascii_case(path.as_bytes())
{
let mut b = p.into_os_string().into_vec();
b.truncate(oss.len());
b.truncate(path.len());
return Ok(PathBuf::from(OsString::from_vec(b)));
}
// Fallback: scan the directory for matching inodes
// Fast path: if the file isn't a symlink
let meta = file.metadata()?;
let mut entries: Vec<_> = std::fs::read_dir(parent)?
.filter_map(Result::ok)
.filter_map(|e| e.metadata().ok().map(|m| (e, m)))
.filter(|(_, m)| m.dev() == meta.dev() && m.ino() == meta.ino())
.map(|(e, _)| e.path())
.collect();
if !meta.is_symlink()
&& let Some(n) = path.canonicalize()?.file_name()
{
return Ok(parent.join(n));
}
if entries.len() == 1 {
// Fallback: scan the directory for matching inodes
let mut names = vec![];
for entry in std::fs::read_dir(parent)? {
let entry = entry?;
let n = entry.file_name(); // TODO: use `file_name_ref()` when stabilized
if n == name {
return Ok(PathBuf::from(OsString::from_vec(cstr.into_bytes())));
} else if let m = entry.metadata()?
&& m.ino() == meta.ino()
&& m.dev() == meta.dev()
{
names.push(n);
}
}
if names.len() == 1 {
// No hardlink that shares the same inode
Ok(entries.remove(0))
} else if let Some(i) = entries.iter().position(|p| p == path) {
// Exact match
Ok(entries.swap_remove(i))
} else if let Some(i) = entries.iter().position(|p| p.as_os_str().eq_ignore_ascii_case(oss)) {
Ok(parent.join(&names[0]))
} else if let mut it = names.iter().enumerate().filter(|&(_, n)| n.eq_ignore_ascii_case(name))
&& let Some((i, _)) = it.next()
&& it.next().is_none()
{
// Case-insensitive match
Ok(entries.swap_remove(i))
Ok(parent.join(&names[i]))
} else {
Err(io::Error::from(io::ErrorKind::NotFound))
}

View file

@ -42,5 +42,8 @@ function Progress:redraw()
end
label = label .. string.format("%d left", summary.total - summary.success)
return gauge:percent(percent):label(ui.Span(label):style(th.status.progress_label))
return {
ui.Clear(self._area),
gauge:percent(percent):label(ui.Span(label):style(th.status.progress_label)),
}
end

View file

@ -392,8 +392,8 @@ impl Scheduler {
let Some(task) = ongoing.get_mut(op.id) else { continue };
op.out.reduce(task);
if !task.prog.cooked() {
continue; // Not cooked yet
if !task.prog.cooked() && task.done.completed() != Some(false) {
continue; // Not cooked yet, also not canceled
} else if task.prog.cleaned() == Some(false) {
continue; // Failed to clean up
} else if let Some(hook) = task.hook.take() {

View file

@ -214,23 +214,22 @@ impl Cmd {
impl Display for Cmd {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name)?;
for i in 0..self.args.len() {
let Ok(s) = self.get::<&str>(i) else { break };
write!(f, " {s}")?;
}
for (k, v) in &self.args {
match k {
DataKey::Integer(_) => {
if let Some(s) = v.as_str() {
write!(f, " {s}")?;
}
if let DataKey::String(k) = k {
if v.try_into().is_ok_and(|b| b) {
write!(f, " --{k}")?;
} else if let Some(s) = v.as_str() {
write!(f, " --{k}={s}")?;
}
DataKey::String(k) => {
if v.try_into().is_ok_and(|b| b) {
write!(f, " --{k}")?;
} else if let Some(s) = v.as_str() {
write!(f, " --{k}={s}")?;
}
}
_ => {}
}
}
Ok(())
}
}

View file

@ -17,6 +17,14 @@ pub enum JoinError {
FromPathDyn(#[from] PathDynError),
}
impl From<StartsWithError> for JoinError {
fn from(err: StartsWithError) -> Self {
match err {
StartsWithError::FromStrand(e) => Self::FromStrand(e),
}
}
}
impl From<JoinError> for std::io::Error {
fn from(err: JoinError) -> Self { Self::other(err) }
}

View file

@ -269,14 +269,25 @@ impl<'a> Url<'a> {
Ok(match self {
Self::Regular(_) => UrlBuf::Regular(joined.into_os()?.into()),
Self::Search { loc, domain } => UrlBuf::Search {
Self::Search { loc, domain } if joined.try_starts_with(loc.base())? => UrlBuf::Search {
loc: LocBuf::<PathBuf>::new(joined.try_into()?, loc.base(), loc.base()),
domain: domain.intern(),
},
Self::Archive { loc, domain } => UrlBuf::Archive {
Self::Search { domain, .. } => UrlBuf::Search {
loc: LocBuf::<PathBuf>::zeroed(joined.into_os()?),
domain: domain.intern(),
},
Self::Archive { loc, domain } if joined.try_starts_with(loc.base())? => UrlBuf::Archive {
loc: LocBuf::<PathBuf>::floated(joined.try_into()?, loc.base()),
domain: domain.intern(),
},
Self::Archive { domain, .. } => UrlBuf::Archive {
loc: LocBuf::<PathBuf>::zeroed(joined.into_os()?),
domain: domain.intern(),
},
Self::Sftp { domain, .. } => {
UrlBuf::Sftp { loc: joined.into_unix()?.into(), domain: domain.intern() }
}

View file

@ -64,6 +64,8 @@ impl<'a> Provider for Sftp<'a> {
return Ok(entry.url());
} else if similar.is_none() {
similar = Some(s.into_owned());
} else {
return Err(io::Error::from(io::ErrorKind::NotFound));
}
}