mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Fix OneDrive casefold crash by handling long paths in GetFinalPathNameByHandleW
Co-authored-by: sxyazi <17523360+sxyazi@users.noreply.github.com>
This commit is contained in:
parent
6a5b5d41da
commit
6eac0a95ec
1 changed files with 22 additions and 0 deletions
|
|
@ -148,6 +148,28 @@ fn final_path(path: &Path) -> io::Result<PathBuf> {
|
|||
|
||||
if len == 0 {
|
||||
Err(io::Error::last_os_error())
|
||||
} else if len as usize > buf.len() {
|
||||
// Buffer too small, allocate a larger buffer and retry
|
||||
let mut large_buf = vec![0u16; len as usize];
|
||||
let new_len = unsafe {
|
||||
GetFinalPathNameByHandleW(
|
||||
file.as_raw_handle() as HANDLE,
|
||||
large_buf.as_mut_ptr(),
|
||||
large_buf.len() as u32,
|
||||
VOLUME_NAME_DOS,
|
||||
)
|
||||
};
|
||||
|
||||
if new_len == 0 {
|
||||
Err(io::Error::last_os_error())
|
||||
} else if new_len as usize > large_buf.len() {
|
||||
// Still too large, give up
|
||||
Err(io::Error::new(io::ErrorKind::InvalidInput, "Path too long"))
|
||||
} else if large_buf.starts_with(&[92, 92, 63, 92]) {
|
||||
Ok(PathBuf::from(OsString::from_wide(&large_buf[4..new_len as usize])))
|
||||
} else {
|
||||
Ok(PathBuf::from(OsString::from_wide(&large_buf[0..new_len as usize])))
|
||||
}
|
||||
} else if buf.starts_with(&[92, 92, 63, 92]) {
|
||||
Ok(PathBuf::from(OsString::from_wide(&buf[4..len as usize])))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue