mirror of
https://github.com/sxyazi/yazi.git
synced 2024-09-11 18:38:19 +03:00
feat: keep file creation time on macOS (#1169)
This commit is contained in:
parent
b5b6c9642a
commit
1f562031f4
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -1205,9 +1205,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mlua"
|
||||
version = "0.9.8"
|
||||
version = "0.9.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e340c022072f3208a4105458286f4985ba5355bfe243c3073afe45cbe9ecf491"
|
||||
checksum = "d111deb18a9c9bd33e1541309f4742523bfab01d276bfa9a27519f6de9c11dc7"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"erased-serde",
|
||||
@ -1223,9 +1223,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mlua-sys"
|
||||
version = "0.6.0"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5552e7e4e22ada0463dfdeee6caf6dc057a189fdc83136408a8f950a5e5c5540"
|
||||
checksum = "a088ed0723df7567f569ba018c5d48c23c501f3878b190b04144dfa5ebfa8abc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
@ -1677,9 +1677,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
@ -2955,7 +2955,6 @@ dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"crossterm",
|
||||
"dirs",
|
||||
"filetime",
|
||||
"futures",
|
||||
"libc",
|
||||
"parking_lot",
|
||||
|
@ -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"
|
||||
|
@ -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" ] }
|
||||
|
@ -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"
|
||||
|
@ -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())
|
||||
})?,
|
||||
)?;
|
||||
|
@ -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" ] }
|
||||
|
@ -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"
|
||||
|
@ -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]
|
||||
@ -104,12 +103,23 @@ 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();
|
||||
}
|
||||
|
||||
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)),
|
||||
|
Loading…
Reference in New Issue
Block a user