@@ -478,7 +478,7 @@ def remove_old_header(file_path, encoding, num_of_chars):
478478 shutil .move (temp_file .name , file_path )
479479
480480
481- def fix_copyright (path , copyright_text , encoding , offset , config = None ):
481+ def fix_copyright (path , copyright_text , encoding , offset , config = None ) -> bool :
482482 """
483483 Inserts a copyright header into the specified file, ensuring that existing
484484 content is preserved according to the provided offset.
@@ -493,6 +493,8 @@ def fix_copyright(path, copyright_text, encoding, offset, config=None):
493493 are preserved.
494494 config (Path): Path to the config JSON file where configuration
495495 variables are stored (e.g. years for copyright headers).
496+ Returns:
497+ bool: True if the copyright header was successfully added, False if there was an error
496498 """
497499
498500 temporary_file = create_temp_file (path , encoding )
@@ -503,7 +505,7 @@ def fix_copyright(path, copyright_text, encoding, offset, config=None):
503505
504506 if offset > 0 and offset != byte_array :
505507 LOGGER .error ("Invalid offset value: %d, expected: %d" , offset , byte_array )
506- return
508+ return False
507509
508510 with open (path , "w" , encoding = encoding ) as handle :
509511 temp .seek (0 )
@@ -518,6 +520,7 @@ def fix_copyright(path, copyright_text, encoding, offset, config=None):
518520 for chunk in iter (lambda : temp .read (4096 ), "" ):
519521 handle .write (chunk )
520522 LOGGER .info ("Fixed missing header in: %s" , path )
523+ return True
521524
522525
523526def process_files (
@@ -583,9 +586,12 @@ def process_files(
583586 if fix :
584587 if remove_offset :
585588 remove_old_header (item , encoding , remove_offset )
586- fix_copyright (item , templates [key ], encoding , effective_offset , config )
589+ fix_result = fix_copyright (
590+ item , templates [key ], encoding , effective_offset , config
591+ )
587592 results ["no_copyright" ] += 1
588- results ["fixed" ] += 1
593+ if fix_result :
594+ results ["fixed" ] += 1
589595 else :
590596 LOGGER .error (
591597 "Missing copyright header in: %s, use --fix to introduce it" , item
0 commit comments