@@ -194,6 +194,25 @@ maybe_flush_buffer(State = #qs{ write_buffer_size = WriteBufferSize }) ->
194
194
false -> State
195
195
end .
196
196
197
+ open_eventually (File , Modes ) ->
198
+ open_eventually (File , Modes , 3 ).
199
+
200
+ open_eventually (_ , _ , 0 ) ->
201
+ {error , eacces };
202
+ open_eventually (File , Modes , N ) ->
203
+ case file :open (File , Modes ) of
204
+ OK = {ok , _ } ->
205
+ OK ;
206
+ % % When the current write file was recently deleted it
207
+ % % is possible on Windows to get an {error,eacces}.
208
+ % % Sometimes Windows sets the files to "DELETE PENDING"
209
+ % % state and delays deletion a bit. So we wait 10ms and
210
+ % % try again up to 3 times.
211
+ {error , eacces } ->
212
+ timer :sleep (10 ),
213
+ open_eventually (File , Modes , N - 1 )
214
+ end .
215
+
197
216
flush_buffer (State = # qs { write_buffer_size = 0 }, _ ) ->
198
217
State ;
199
218
flush_buffer (State0 = # qs { write_buffer = WriteBuffer }, FsyncFun ) ->
@@ -204,7 +223,7 @@ flush_buffer(State0 = #qs{ write_buffer = WriteBuffer }, FsyncFun) ->
204
223
Writes = flush_buffer_build (WriteList , CheckCRC32 , SegmentEntryCount ),
205
224
% % Then we do the writes for each segment.
206
225
State = lists :foldl (fun ({Segment , LocBytes }, FoldState ) ->
207
- {ok , Fd } = file : open (segment_file (Segment , FoldState ), [read , write , raw , binary ]),
226
+ {ok , Fd } = open_eventually (segment_file (Segment , FoldState ), [read , write , raw , binary ]),
208
227
case file :position (Fd , eof ) of
209
228
{ok , 0 } ->
210
229
% % We write the file header if it does not exist.
0 commit comments