@@ -501,7 +501,7 @@ def recover_backup_files(self):
501501 try :
502502 # First try to validate the backup file
503503 with open (src , 'rb' ) as fp :
504- try :
504+ try :
505505 # Try to read the entire file first to check for EOF
506506 content = fp .read ()
507507 if not content :
@@ -511,86 +511,86 @@ def recover_backup_files(self):
511511 from io import BytesIO
512512 fp = BytesIO (content )
513513
514- try :
515- msg = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
516- data_pos = fp .tell ()
517- data = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
514+ try :
515+ msg = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
516+ data_pos = fp .tell ()
517+ data = pickle .load (fp , fix_imports = True , encoding = 'latin1' )
518518 except (EOFError , pickle .UnpicklingError ) as e :
519519 mailman_log ('error' , 'Corrupted backup file %s: %s\n Traceback:\n %s' ,
520520 filebase , str (e ), traceback .format_exc ())
521- self .finish (filebase , preserve = True )
522- continue
523-
521+ self .finish (filebase , preserve = True )
522+ continue
523+
524524 # Validate the unpickled data
525525 if not isinstance (data , dict ):
526526 raise TypeError ('Invalid data format in backup file' )
527527
528528 # Update metadata
529- data ['_bak_count' ] = data .setdefault ('_bak_count' , 0 ) + 1
530- data ['_last_attempt' ] = time .time ()
531- if '_error_history' not in data :
532- data ['_error_history' ] = []
533- if '_traceback' in data :
534- data ['_error_history' ].append ({
535- 'error' : data .get ('_last_error' , 'unknown' ),
536- 'traceback' : data .get ('_traceback' , 'none' ),
537- 'time' : data .get ('_last_attempt' , 0 )
538- })
529+ data ['_bak_count' ] = data .setdefault ('_bak_count' , 0 ) + 1
530+ data ['_last_attempt' ] = time .time ()
531+ if '_error_history' not in data :
532+ data ['_error_history' ] = []
533+ if '_traceback' in data :
534+ data ['_error_history' ].append ({
535+ 'error' : data .get ('_last_error' , 'unknown' ),
536+ 'traceback' : data .get ('_traceback' , 'none' ),
537+ 'time' : data .get ('_last_attempt' , 0 )
538+ })
539539
540540 # Write the updated data back
541541 with open (src , 'wb' ) as out_fp :
542- if data .get ('_parsemsg' ):
543- protocol = 0
544- else :
545- protocol = 1
542+ if data .get ('_parsemsg' ):
543+ protocol = 0
544+ else :
545+ protocol = 1
546546 pickle .dump (data , out_fp , protocol = 4 , fix_imports = True )
547547 out_fp .flush ()
548548 if hasattr (os , 'fsync' ):
549549 os .fsync (out_fp .fileno ())
550-
551- # Log detailed information about the retry
552- mailman_log ('warning' ,
553- 'Message retry attempt %d/%d: %s (queue: %s, '
554- 'message-id: %s, listname: %s, recipients: %s, '
555- 'error: %s, last attempt: %s, traceback: %s)' ,
556- data ['_bak_count' ],
550+
551+ # Log detailed information about the retry
552+ mailman_log ('warning' ,
553+ 'Message retry attempt %d/%d: %s (queue: %s, '
554+ 'message-id: %s, listname: %s, recipients: %s, '
555+ 'error: %s, last attempt: %s, traceback: %s)' ,
556+ data ['_bak_count' ],
557+ MAX_BAK_COUNT ,
558+ filebase ,
559+ self .__whichq ,
560+ data .get ('message-id' , 'unknown' ),
561+ data .get ('listname' , 'unknown' ),
562+ data .get ('recips' , 'unknown' ),
563+ data .get ('_last_error' , 'unknown' ),
564+ time .ctime (data .get ('_last_attempt' , 0 )),
565+ data .get ('_traceback' , 'none' ))
566+
567+ if data ['_bak_count' ] >= MAX_BAK_COUNT :
568+ mailman_log ('error' ,
569+ 'Backup file exceeded maximum retry count (%d). '
570+ 'Moving to shunt queue: %s (original queue: %s, '
571+ 'retry count: %d, last error: %s, '
572+ 'message-id: %s, listname: %s, '
573+ 'recipients: %s, error history: %s, '
574+ 'last traceback: %s, full path: %s)' ,
557575 MAX_BAK_COUNT ,
558576 filebase ,
559577 self .__whichq ,
578+ data ['_bak_count' ],
579+ data .get ('_last_error' , 'unknown' ),
560580 data .get ('message-id' , 'unknown' ),
561581 data .get ('listname' , 'unknown' ),
562582 data .get ('recips' , 'unknown' ),
563- data .get ('_last_error' , 'unknown' ),
564- time .ctime (data .get ('_last_attempt' , 0 )),
565- data .get ('_traceback' , 'none' ))
566-
567- if data ['_bak_count' ] >= MAX_BAK_COUNT :
568- mailman_log ('error' ,
569- 'Backup file exceeded maximum retry count (%d). '
570- 'Moving to shunt queue: %s (original queue: %s, '
571- 'retry count: %d, last error: %s, '
572- 'message-id: %s, listname: %s, '
573- 'recipients: %s, error history: %s, '
574- 'last traceback: %s, full path: %s)' ,
575- MAX_BAK_COUNT ,
576- filebase ,
577- self .__whichq ,
578- data ['_bak_count' ],
579- data .get ('_last_error' , 'unknown' ),
580- data .get ('message-id' , 'unknown' ),
581- data .get ('listname' , 'unknown' ),
582- data .get ('recips' , 'unknown' ),
583- data .get ('_error_history' , 'unknown' ),
584- data .get ('_traceback' , 'none' ),
585- os .path .join (self .__whichq , filebase + '.bak' ))
583+ data .get ('_error_history' , 'unknown' ),
584+ data .get ('_traceback' , 'none' ),
585+ os .path .join (self .__whichq , filebase + '.bak' ))
586+ self .finish (filebase , preserve = True )
587+ else :
588+ try :
589+ os .rename (src , dst )
590+ except OSError as e :
591+ mailman_log ('error' , 'Failed to rename backup file %s (full paths: %s -> %s): %s\n Traceback:\n %s' ,
592+ filebase , os .path .join (self .__whichq , filebase + '.bak' ), os .path .join (self .__whichq , filebase + '.pck' ), str (e ), traceback .format_exc ())
586593 self .finish (filebase , preserve = True )
587- else :
588- try :
589- os .rename (src , dst )
590- except OSError as e :
591- mailman_log ('error' , 'Failed to rename backup file %s (full paths: %s -> %s): %s\n Traceback:\n %s' ,
592- filebase , os .path .join (self .__whichq , filebase + '.bak' ), os .path .join (self .__whichq , filebase + '.pck' ), str (e ), traceback .format_exc ())
593- self .finish (filebase , preserve = True )
594594
595595 except Exception as e :
596596 mailman_log ('error' , 'Failed to process backup file %s (full path: %s): %s\n Traceback:\n %s' ,
0 commit comments