diff --git a/Cargo.lock b/Cargo.lock index 96bfa28d..1608b935 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2910,6 +2910,7 @@ dependencies = [ "bitflags 2.5.0", "crossterm", "dirs", + "filetime", "futures", "libc", "parking_lot", diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 061177b7..62868471 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -13,6 +13,7 @@ anyhow = "1.0.82" bitflags = "2.5.0" crossterm = "0.27.0" dirs = "5.0.1" +filetime = "0.2.23" futures = "0.3.30" parking_lot = "0.12.1" percent-encoding = "2.3.1" diff --git a/yazi-shared/src/fs/fns.rs b/yazi-shared/src/fs/fns.rs index 9811a5bd..3e8f208c 100644 --- a/yazi-shared/src/fs/fns.rs +++ b/yazi-shared/src/fs/fns.rs @@ -1,6 +1,7 @@ use std::{collections::VecDeque, path::{Path, PathBuf}}; use anyhow::Result; +use filetime::{set_file_times, FileTime}; use tokio::{fs, io, select, sync::{mpsc, oneshot}, time}; pub async fn accessible(path: &Path) -> bool { @@ -42,8 +43,17 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver tick_tx.send(Ok(len)), + _ = match fs::copy(&from, &to).await { + Ok(len) => { + // Attempt to preserve file's accessed at and modified at timestamps + if let Ok(metadata) = fs::metadata(from).await { + let mtime = FileTime::from_last_modification_time(&metadata); + let atime = FileTime::from_last_access_time(&metadata); + _ = set_file_times(to, atime, mtime); + }; + + tick_tx.send(Ok(len)) + } Err(e) => tick_tx.send(Err(e)), }; }