File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
223223pub 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}
Original file line number Diff line number Diff line change @@ -59,8 +59,19 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<PathB
5959}
6060
6161pub 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
Original file line number Diff line number Diff line change @@ -95,13 +95,23 @@ pub fn ensure_version_dir(base_path: &Path, version_id: u64) -> Result<PathBuf>
9595}
9696
9797pub 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}
Original file line number Diff line number Diff line change @@ -81,13 +81,23 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<std::
8181}
8282
8383pub 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}
Original file line number Diff line number Diff line change @@ -128,13 +128,23 @@ pub fn ensure_version_dir(base_path: &Path, version_number: u64) -> Result<std::
128128}
129129
130130pub 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}
You can’t perform that action at this time.
0 commit comments