Skip to content

Commit

Permalink
feat: keep file creation time on macOS and Windows (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jun 20, 2024
1 parent b5b6c96 commit 0f84717
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yazi-dds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
anyhow = "1.0.86"
mlua = { version = "0.9.8", features = [ "lua54" ] }
mlua = { version = "0.9.9", features = [ "lua54" ] }
parking_lot = "0.12.3"
serde = { version = "1.0.203", features = [ "derive" ] }
serde_json = "1.0.117"
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ better-panic = "0.3.0"
crossterm = { version = "0.27.0", features = [ "event-stream" ] }
fdlimit = "0.3.0"
futures = "0.3.30"
mlua = { version = "0.9.8", features = [ "lua54" ] }
mlua = { version = "0.9.9", features = [ "lua54" ] }
ratatui = "0.26.3"
scopeguard = "1.2.0"
syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ base64 = "0.22.1"
crossterm = "0.27.0"
futures = "0.3.30"
md-5 = "0.10.6"
mlua = { version = "0.9.8", features = [ "lua54", "serialize", "macros", "async" ] }
mlua = { version = "0.9.9", features = [ "lua54", "serialize", "macros", "async" ] }
parking_lot = "0.12.3"
ratatui = "0.26.3"
serde = "1.0.203"
Expand Down
11 changes: 6 additions & 5 deletions yazi-plugin/src/utils/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ impl Utils {
pub(super) fn text(lua: &Lua, ya: &Table) -> mlua::Result<()> {
ya.raw_set(
"quote",
lua.create_function(|_, s: mlua::String| {
#[cfg(unix)]
let s = shell_escape::unix::escape(s.to_str()?.into());
#[cfg(windows)]
let s = shell_escape::windows::escape(s.to_str()?.into());
lua.create_function(|_, (s, unix): (mlua::String, Option<bool>)| {
let s = match unix {
Some(true) => shell_escape::unix::escape(s.to_str()?.into()),
Some(false) => shell_escape::windows::escape(s.to_str()?.into()),
None => shell_escape::escape(s.to_str()?.into()),
};
Ok(s.into_owned())
})?,
)?;
Expand Down
2 changes: 1 addition & 1 deletion yazi-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
anyhow = "1.0.86"
mlua = { version = "0.9.8", features = [ "lua54" ] }
mlua = { version = "0.9.9", features = [ "lua54" ] }
tokio = { version = "1.38.0", features = [ "full" ] }
1 change: 0 additions & 1 deletion yazi-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ anyhow = "1.0.86"
bitflags = "2.5.0"
crossterm = "0.27.0"
dirs = "5.0.1"
filetime = "0.2.23"
futures = "0.3.30"
parking_lot = "0.12.3"
percent-encoding = "2.3.1"
Expand Down
21 changes: 18 additions & 3 deletions yazi-shared/src/fs/fns.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{borrow::Cow, collections::{HashMap, VecDeque}, fs::Metadata, path::{Path, PathBuf}};

use anyhow::Result;
use filetime::{set_file_mtime, FileTime};
use tokio::{fs, io, select, sync::{mpsc, oneshot}, time};

#[inline]
Expand Down Expand Up @@ -104,12 +103,28 @@ pub fn copy_with_progress(

tokio::spawn({
let (from, to) = (from.to_owned(), to.to_owned());
let mtime = FileTime::from_last_modification_time(meta);

let mut ft = std::fs::FileTimes::new();
meta.accessed().map(|t| ft = ft.set_accessed(t)).ok();
meta.modified().map(|t| ft = ft.set_modified(t)).ok();
#[cfg(target_os = "macos")]
{
use std::os::macos::fs::FileTimesExt;
meta.created().map(|t| ft = ft.set_created(t)).ok();
}
#[cfg(windows)]
{
use std::os::windows::fs::FileTimesExt;
meta.created().map(|t| ft = ft.set_created(t)).ok();
}

async move {
_ = match fs::copy(&from, &to).await {
Ok(len) => {
set_file_mtime(to, mtime).ok();
_ = tokio::task::spawn_blocking(move || {
std::fs::File::options().write(true).open(to).and_then(|f| f.set_times(ft)).ok();
})
.await;
tick_tx.send(Ok(len))
}
Err(e) => tick_tx.send(Err(e)),
Expand Down

0 comments on commit 0f84717

Please sign in to comment.