fix(compat): [#1981] Windows平台sync_parent_dir兼容修复
- sync_parent_dir新增#[cfg(windows)]空实现 - File导入改为条件编译避免Windows编译失败 - 版本号升级至v0.5.3
This commit is contained in:
Generated
+1
-1
@@ -261,7 +261,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "l-s"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "l-s"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
authors = ["licsber <admin@licsber.site>"]
|
||||
edition = "2021"
|
||||
|
||||
|
||||
+12
-1
@@ -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<Option<fs::Metadata>> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user