From 844b366f6239b85bf775afa06c20207fcc88d3c6 Mon Sep 17 00:00:00 2001 From: licsber Date: Fri, 15 May 2026 14:37:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(compat):=20[#1981]=20Windows=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0sync=5Fparent=5Fdir=E5=85=BC=E5=AE=B9=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sync_parent_dir新增#[cfg(windows)]空实现 - File导入改为条件编译避免Windows编译失败 - 版本号升级至v0.5.3 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28413c9..9fbe59b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,7 +261,7 @@ dependencies = [ [[package]] name = "l-s" -version = "0.5.2" +version = "0.5.3" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 70884b2..437914e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "l-s" -version = "0.5.2" +version = "0.5.3" authors = ["licsber "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 25b4551..744669a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,9 @@ mod head_hash; mod meta; mod utils; -use std::fs::{self, File, OpenOptions}; +#[cfg(not(windows))] +use std::fs::File; +use std::fs::{self, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::time::{Instant, SystemTime, UNIX_EPOCH}; @@ -243,6 +245,7 @@ fn symlink_metadata_optional(path: &Path) -> Result> { } } +#[cfg(not(windows))] fn sync_parent_dir(path: &Path) -> Result<()> { let parent = path.parent().unwrap_or_else(|| Path::new(".")); let dir = File::open(parent) @@ -250,3 +253,11 @@ fn sync_parent_dir(path: &Path) -> Result<()> { dir.sync_all() .with_context(|| format!("无法同步父目录: {}", parent.display())) } + +#[cfg(windows)] +fn sync_parent_dir(_path: &Path) -> Result<()> { + // Windows does not support the Unix-style parent directory fsync used here + // through std::fs::File::open. The data file itself is still synced before + // rename; directory syncing is a best-effort durability step on Unix. + Ok(()) +}