Skip to content

Commit a133f33

Browse files
committed
Avoid sync dir on windows
1 parent 738933c commit a133f33

5 files changed

Lines changed: 77 additions & 26 deletions

File tree

src/bool/io.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,23 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<std::
221221

222222
/// Sync a directory to ensure file operations are durable.
223223
pub fn sync_dir(path: &Path) -> Result<()> {
224-
let dir = OpenOptions::new()
225-
.read(true)
226-
.open(path)
227-
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
224+
// On Unix, we can sync the directory
225+
#[cfg(unix)]
226+
{
227+
let dir = OpenOptions::new()
228+
.read(true)
229+
.open(path)
230+
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
231+
232+
dir.sync_all()
233+
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
234+
}
228235

229-
dir.sync_all()
230-
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
236+
// On non-Unix, this is a no-op
237+
#[cfg(not(unix))]
238+
{
239+
let _ = path;
240+
}
231241

232242
Ok(())
233243
}

src/embedding/io.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,19 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<PathB
5959
}
6060

6161
pub fn sync_dir(path: &Path) -> Result<(), Error> {
62-
let dir = OpenOptions::new().read(true).open(path)?;
63-
dir.sync_all()?;
62+
// On Unix, we can sync the directory
63+
#[cfg(unix)]
64+
{
65+
let dir = OpenOptions::new().read(true).open(path)?;
66+
dir.sync_all()?;
67+
}
68+
69+
// On non-Unix, this is a no-op
70+
#[cfg(not(unix))]
71+
{
72+
let _ = path;
73+
}
74+
6475
Ok(())
6576
}
6677

src/geopoint/io.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,23 @@ pub fn ensure_version_dir(base_path: &Path, version_id: u64) -> Result<PathBuf>
9595
}
9696

9797
pub fn sync_dir(path: &Path) -> Result<()> {
98-
let dir = OpenOptions::new()
99-
.read(true)
100-
.open(path)
101-
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
98+
// On Unix, we can sync the directory
99+
#[cfg(unix)]
100+
{
101+
let dir = OpenOptions::new()
102+
.read(true)
103+
.open(path)
104+
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
105+
106+
dir.sync_all()
107+
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
108+
}
102109

103-
dir.sync_all()
104-
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
110+
// On non-Unix, this is a no-op
111+
#[cfg(not(unix))]
112+
{
113+
let _ = path;
114+
}
105115

106116
Ok(())
107117
}

src/string/io.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,23 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<std::
8181
}
8282

8383
pub fn sync_dir(path: &Path) -> Result<()> {
84-
let dir = OpenOptions::new()
85-
.read(true)
86-
.open(path)
87-
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
84+
// On Unix, we can sync the directory
85+
#[cfg(unix)]
86+
{
87+
let dir = OpenOptions::new()
88+
.read(true)
89+
.open(path)
90+
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
91+
92+
dir.sync_all()
93+
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
94+
}
8895

89-
dir.sync_all()
90-
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
96+
// On non-Unix, this is a no-op
97+
#[cfg(not(unix))]
98+
{
99+
let _ = path;
100+
}
91101

92102
Ok(())
93103
}

src/string_filter/io.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,23 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<std::
128128
}
129129

130130
pub fn sync_dir(path: &Path) -> Result<()> {
131-
let dir = OpenOptions::new()
132-
.read(true)
133-
.open(path)
134-
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
131+
// On Unix, we can sync the directory
132+
#[cfg(unix)]
133+
{
134+
let dir = OpenOptions::new()
135+
.read(true)
136+
.open(path)
137+
.with_context(|| format!("Failed to open directory for sync: {path:?}"))?;
138+
139+
dir.sync_all()
140+
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
141+
}
135142

136-
dir.sync_all()
137-
.with_context(|| format!("Failed to sync directory: {path:?}"))?;
143+
// On non-Unix, this is a no-op
144+
#[cfg(not(unix))]
145+
{
146+
let _ = path;
147+
}
138148

139149
Ok(())
140150
}

0 commit comments

Comments
 (0)