@@ -276,6 +276,28 @@ impl FileAppender {
276276
277277 let _ = self . file . take ( ) ;
278278
279+ #[ cfg( windows) ]
280+ {
281+ if let Err ( err) = self . rotate_old_files ( ) {
282+ const ERROR_SHARING_VIOLATION : i32 = 32 ;
283+
284+ // To avoid the problem reported by https://github.com/sile/sloggers/issues/43,
285+ // we ignore the error if its code is 32.
286+ if err. raw_os_error ( ) != Some ( ERROR_SHARING_VIOLATION ) {
287+ return Err ( err) ;
288+ }
289+ }
290+ }
291+ #[ cfg( not( windows) ) ]
292+ self . rotate_old_files ( ) ?;
293+
294+ self . written_size = 0 ;
295+ self . next_reopen_check = Instant :: now ( ) ;
296+ self . reopen_if_needed ( ) ?;
297+
298+ Ok ( ( ) )
299+ }
300+ fn rotate_old_files ( & mut self ) -> io:: Result < ( ) > {
279301 for i in ( 1 ..=self . rotate_keep ) . rev ( ) {
280302 let from = self . rotated_path ( i) ?;
281303 let to = self . rotated_path ( i + 1 ) ?;
@@ -311,10 +333,6 @@ impl FileAppender {
311333 fs:: remove_file ( delete_path) ?;
312334 }
313335
314- self . written_size = 0 ;
315- self . next_reopen_check = Instant :: now ( ) ;
316- self . reopen_if_needed ( ) ?;
317-
318336 Ok ( ( ) )
319337 }
320338 fn rotated_path ( & self , i : usize ) -> io:: Result < PathBuf > {
@@ -527,9 +545,9 @@ fn path_template_to_path(
527545 let timestamp_string = match timezone {
528546 TimeZone :: Local => {
529547 let local_timestamp = Local . from_utc_datetime ( & date_time. naive_utc ( ) ) ;
530- local_timestamp. format ( & timestamp_template)
548+ local_timestamp. format ( timestamp_template)
531549 }
532- TimeZone :: Utc => date_time. format ( & timestamp_template) ,
550+ TimeZone :: Utc => date_time. format ( timestamp_template) ,
533551 }
534552 . to_string ( ) ;
535553 let path_string = path_template. replace ( "{timestamp}" , & timestamp_string) ;
0 commit comments