mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Fix: rename sensitivity
This commit is contained in:
parent
505de05d66
commit
6aa124c77b
3 changed files with 19 additions and 8 deletions
|
|
@ -6,7 +6,7 @@ use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
|||
use yazi_config::{OPEN, PREVIEW};
|
||||
use yazi_dds::Pubsub;
|
||||
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::{are_paths_equal, max_common_root, maybe_exists, File, FilesOp, Url}, terminal_clear};
|
||||
|
||||
use crate::manager::Manager;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ impl Manager {
|
|||
for (o, n) in todo {
|
||||
let (old, new) = (root.join(&o), root.join(&n));
|
||||
|
||||
if maybe_exists(&new).await {
|
||||
if maybe_exists(&new).await && !are_paths_equal(&old, &new).await {
|
||||
failed.push((o, n, anyhow!("Destination already exists")));
|
||||
} else if let Err(e) = fs::rename(&old, &new).await {
|
||||
failed.push((o, n, e.into()));
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use tokio::fs;
|
|||
use yazi_config::popup::InputCfg;
|
||||
use yazi_dds::Pubsub;
|
||||
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::{are_paths_equal, maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}};
|
||||
|
||||
use crate::manager::Manager;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ impl Manager {
|
|||
}
|
||||
|
||||
let new = hovered.parent().unwrap().join(name);
|
||||
if opt.force || !maybe_exists(&new).await {
|
||||
if opt.force || !maybe_exists(&new).await || are_paths_equal(&hovered, &new).await {
|
||||
Self::rename_do(tab, hovered, Url::from(new)).await.ok();
|
||||
return;
|
||||
}
|
||||
|
|
@ -81,14 +81,17 @@ impl Manager {
|
|||
let Some(p_new) = new.parent_url() else { return Ok(()) };
|
||||
let _permit = WATCHER.acquire().await.unwrap();
|
||||
|
||||
let are_different = !are_paths_equal(&old, &new).await;
|
||||
let overwritten = symlink_realpath(&new).await;
|
||||
fs::rename(&old, &new).await?;
|
||||
|
||||
if let Ok(p) = overwritten {
|
||||
ok_or_not_found(fs::rename(&p, &new).await)?;
|
||||
FilesOp::Deleting(p_new.clone(), vec![Url::from(p)]).emit();
|
||||
if are_different {
|
||||
if let Ok(p) = overwritten {
|
||||
ok_or_not_found(fs::rename(&p, &new).await)?;
|
||||
FilesOp::Deleting(p_new.clone(), vec![Url::from(p)]).emit();
|
||||
}
|
||||
Pubsub::pub_from_rename(tab, &old, &new);
|
||||
}
|
||||
Pubsub::pub_from_rename(tab, &old, &new);
|
||||
|
||||
let file = File::from(new.clone()).await?;
|
||||
FilesOp::Deleting(p_old, vec![old]).emit();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@ pub fn ok_or_not_found(result: io::Result<()>) -> io::Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn are_paths_equal(old: impl AsRef<Path>, new: impl AsRef<Path>) -> bool {
|
||||
match (fs::canonicalize(old).await, fs::canonicalize(new).await) {
|
||||
(Ok(old), Ok(new)) => old == new,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn symlink_realpath(path: &Path) -> Result<PathBuf> {
|
||||
let p = fs::canonicalize(path).await?;
|
||||
if p == path {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue