mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: while copying, preserve files' modified and accessed at timestamps
This commit is contained in:
parent
a0b4ee6e6e
commit
791b801aed
3 changed files with 14 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2910,6 +2910,7 @@ dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"filetime",
|
||||||
"futures",
|
"futures",
|
||||||
"libc",
|
"libc",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ anyhow = "1.0.82"
|
||||||
bitflags = "2.5.0"
|
bitflags = "2.5.0"
|
||||||
crossterm = "0.27.0"
|
crossterm = "0.27.0"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
|
filetime = "0.2.23"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
percent-encoding = "2.3.1"
|
percent-encoding = "2.3.1"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{collections::VecDeque, path::{Path, PathBuf}};
|
use std::{collections::VecDeque, path::{Path, PathBuf}};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use filetime::{set_file_times, FileTime};
|
||||||
use tokio::{fs, io, select, sync::{mpsc, oneshot}, time};
|
use tokio::{fs, io, select, sync::{mpsc, oneshot}, time};
|
||||||
|
|
||||||
pub async fn accessible(path: &Path) -> bool {
|
pub async fn accessible(path: &Path) -> bool {
|
||||||
|
|
@ -42,8 +43,17 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver<Result<u64,
|
||||||
let (from, to) = (from.to_path_buf(), to.to_path_buf());
|
let (from, to) = (from.to_path_buf(), to.to_path_buf());
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
_ = match fs::copy(from, to).await {
|
_ = match fs::copy(&from, &to).await {
|
||||||
Ok(len) => tick_tx.send(Ok(len)),
|
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)),
|
Err(e) => tick_tx.send(Err(e)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue