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(()) +}