mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
e263a0d477
commit
3ad259e1b9
3 changed files with 16 additions and 20 deletions
|
|
@ -6,7 +6,7 @@ use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
||||||
use yazi_config::{OPEN, PREVIEW};
|
use yazi_config::{OPEN, PREVIEW};
|
||||||
use yazi_dds::Pubsub;
|
use yazi_dds::Pubsub;
|
||||||
use yazi_proxy::{AppProxy, TasksProxy, HIDER, WATCHER};
|
use yazi_proxy::{AppProxy, TasksProxy, HIDER, WATCHER};
|
||||||
use yazi_shared::{fs::{max_common_root, maybe_exists, File, FilesOp, Url}, terminal_clear};
|
use yazi_shared::{fs::{max_common_root, maybe_exists, paths_to_same_file, File, FilesOp, Url}, terminal_clear};
|
||||||
|
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
||||||
|
|
@ -84,23 +84,14 @@ impl Manager {
|
||||||
for (o, n) in todo {
|
for (o, n) in todo {
|
||||||
let (old, new) = (root.join(&o), root.join(&n));
|
let (old, new) = (root.join(&o), root.join(&n));
|
||||||
|
|
||||||
if maybe_exists(&new).await {
|
if maybe_exists(&new).await && !paths_to_same_file(&old, &new).await {
|
||||||
failed.push((o, n, anyhow!("Destination already exists")));
|
failed.push((o, n, anyhow!("Destination already exists")));
|
||||||
|
} else if let Err(e) = fs::rename(&old, &new).await {
|
||||||
|
failed.push((o, n, e.into()));
|
||||||
|
} else if let Ok(f) = File::from(new.into()).await {
|
||||||
|
succeeded.insert(Url::from(old), f);
|
||||||
} else {
|
} else {
|
||||||
#[cfg(unix)]
|
failed.push((o, n, anyhow!("Failed to retrieve file info")));
|
||||||
if let Err(e) = fs::rename(&old, &new).await {
|
|
||||||
failed.push((o, n, e.into()));
|
|
||||||
} else if let Ok(f) = File::from(new.into()).await {
|
|
||||||
succeeded.insert(Url::from(old), f);
|
|
||||||
} else {
|
|
||||||
failed.push((o, n, anyhow!("Failed to retrieve file info")));
|
|
||||||
}
|
|
||||||
#[cfg(windows)]
|
|
||||||
if let Ok(f) = File::from(new.into()).await {
|
|
||||||
succeeded.insert(Url::from(old), f);
|
|
||||||
} else {
|
|
||||||
failed.push((o, n, anyhow!("Failed to retrieve file info")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use tokio::fs;
|
||||||
use yazi_config::popup::InputCfg;
|
use yazi_config::popup::InputCfg;
|
||||||
use yazi_dds::Pubsub;
|
use yazi_dds::Pubsub;
|
||||||
use yazi_proxy::{InputProxy, TabProxy, WATCHER};
|
use yazi_proxy::{InputProxy, TabProxy, WATCHER};
|
||||||
use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}};
|
use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, paths_to_same_file, symlink_realpath, File, FilesOp, Url}};
|
||||||
|
|
||||||
use crate::manager::Manager;
|
use crate::manager::Manager;
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ impl Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
let new = hovered.parent().unwrap().join(name);
|
let new = hovered.parent().unwrap().join(name);
|
||||||
if opt.force || !maybe_exists(&new).await {
|
if opt.force || !maybe_exists(&new).await || paths_to_same_file(&hovered, &new).await {
|
||||||
Self::rename_do(tab, hovered, Url::from(new)).await.ok();
|
Self::rename_do(tab, hovered, Url::from(new)).await.ok();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,13 @@ pub fn ok_or_not_found(result: io::Result<()>) -> io::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn paths_to_same_file(a: impl AsRef<Path>, b: impl AsRef<Path>) -> bool {
|
||||||
|
_paths_to_same_file(a.as_ref(), b.as_ref()).await.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub async fn paths_to_same_file(a: &Path, b: &Path) -> io::Result<bool> {
|
async fn _paths_to_same_file(a: &Path, b: &Path) -> io::Result<bool> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
let (a_, b_) = (fs::symlink_metadata(a).await?, fs::symlink_metadata(b).await?);
|
let (a_, b_) = (fs::symlink_metadata(a).await?, fs::symlink_metadata(b).await?);
|
||||||
|
|
@ -36,7 +41,7 @@ pub async fn paths_to_same_file(a: &Path, b: &Path) -> io::Result<bool> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub async fn paths_to_same_file(a: &Path, b: &Path) -> std::io::Result<bool> {
|
async fn _paths_to_same_file(a: &Path, b: &Path) -> std::io::Result<bool> {
|
||||||
use std::os::windows::{ffi::OsStringExt, io::AsRawHandle};
|
use std::os::windows::{ffi::OsStringExt, io::AsRawHandle};
|
||||||
|
|
||||||
use windows_sys::Win32::{Foundation::{HANDLE, MAX_PATH}, Storage::FileSystem::{GetFinalPathNameByHandleW, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, VOLUME_NAME_DOS}};
|
use windows_sys::Win32::{Foundation::{HANDLE, MAX_PATH}, Storage::FileSystem::{GetFinalPathNameByHandleW, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, VOLUME_NAME_DOS}};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue