@@ -865,10 +865,18 @@ def process_sync_results(sync_results, rpm_config, resync_repos, log):
865865 """
866866 Process sync results and determine which repos need publication/distribution.
867867
868+ This function handles two scenarios:
869+ 1. Repos with version changes from current sync - need new publication/distribution
870+ 2. Repos that were synced previously but missing publication/distribution (crash recovery)
871+ - This check is performed for ALL repos regardless of resync_repos setting
872+ - Ensures that if a previous run synced repos A, B, C but failed before creating
873+ pub/dist, a subsequent run (even with resync_repos=["D"]) will still create
874+ the missing pub/dist for A, B, C
875+
868876 Args:
869877 sync_results (list): Results from sync_rpm_repository (success, name, actually_synced, version_changed).
870878 rpm_config (list): List of repository configurations.
871- resync_repos (str/list): Controls which repos to process .
879+ resync_repos (str/list): Controls which repos to sync (not which repos to check for pub/dist) .
872880 log (logging.Logger): Logger instance.
873881
874882 Returns:
@@ -882,112 +890,72 @@ def process_sync_results(sync_results, rpm_config, resync_repos, log):
882890 version_changed_repos = [name for success , name , actually_synced , version_changed in sync_results if success and actually_synced and version_changed ]
883891 log .info (f"Repos with version change: { len (version_changed_repos )} - { version_changed_repos } " )
884892
885- # If no versions changed, check for missing publication/distribution
886- # This handles the crash recovery case: process failed after sync but before pub/dist
887- if not version_changed_repos :
888- log .info ("No version changes detected. Checking for missing publication/distribution." )
889-
890- # Check all synced repos (including previously synced) for missing pub/dist
891- repos_missing_pub_dist = []
892- all_repo_names = []
893- for repo in rpm_config :
894- repo_name = repo ["package" ]
895- version = repo .get ("version" )
896- if version and version != "null" :
897- repo_name = f"{ repo_name } _{ version } "
898- all_repo_names .append (repo_name )
899-
900- # If resync_repos is a specific list, only check those repos
901- if resync_repos and resync_repos != "all" :
902- resync_list = resync_repos if isinstance (resync_repos , list ) else [r .strip () for r in resync_repos .split ("," )]
903- if repo_name not in resync_list :
904- continue
905-
906- pub_exists = check_publication_exists (repo_name , log )
907- dist_exists = check_distribution_exists (repo_name , log )
908-
909- if not pub_exists or not dist_exists :
910- log .info (f"{ repo_name } missing publication={ not pub_exists } , distribution={ not dist_exists } . Including for pub/dist creation." )
911- repo_copy = repo .copy ()
912- repo_copy ["_version_changed" ] = False
913- repos_missing_pub_dist .append (repo_copy )
914-
915- if repos_missing_pub_dist :
916- missing_names = [r ["package" ] for r in repos_missing_pub_dist ]
917- log .info (f"Found { len (repos_missing_pub_dist )} repo(s) missing publication/distribution: { missing_names } " )
918- return repos_missing_pub_dist , False , ""
919-
920- # All repos have publication and distribution - safe to skip
921- log .info ("All repos have existing publication and distribution. Skipping." )
922- if actually_synced_repos :
923- # Repos were synced but no metadata change
924- synced_list = ", " .join (actually_synced_repos )
925- skip_msg = f"Sync successful for { len (actually_synced_repos )} repo(s): { synced_list } . No metadata changes detected - existing publication/distribution retained"
926- else :
927- # No repos were synced at all (already up to date)
928- skip_msg = "All repositories already synced - no updates required"
929- return [], True , skip_msg
930-
931893 repos_for_pub_dist = []
894+ repos_for_pub_dist_names = set () # Track names to avoid duplicates
932895
933- if resync_repos == "all" :
934- log .info ("resync_repos='all' - Processing publication and distribution for repos with version change" )
935- for repo in rpm_config :
936- repo_name = repo ["package" ]
937- version = repo .get ("version" )
938- if version and version != "null" :
939- repo_name = f"{ repo_name } _{ version } "
940- # Only include repos with version change
941- if repo_name in version_changed_repos :
942- repo_copy = repo .copy ()
943- repo_copy ["_version_changed" ] = True
944- repos_for_pub_dist .append (repo_copy )
896+ # Step 1: Add repos with version changes (these definitely need new publication)
897+ for repo in rpm_config :
898+ repo_name = repo ["package" ]
899+ version = repo .get ("version" )
900+ if version and version != "null" :
901+ repo_name = f"{ repo_name } _{ version } "
902+
903+ if repo_name in version_changed_repos :
904+ repo_copy = repo .copy ()
905+ repo_copy ["_version_changed" ] = True
906+ repos_for_pub_dist .append (repo_copy )
907+ repos_for_pub_dist_names .add (repo_name )
908+ log .info (f"{ repo_name } has version change. Including for pub/dist creation." )
909+
910+ # Step 2: Check ALL repos for missing publication/distribution (crash recovery)
911+ # This is independent of resync_repos - we always want to ensure all synced repos
912+ # have their publication/distribution created
913+ log .info ("Checking all repos for missing publication/distribution (crash recovery check)." )
914+
915+ for repo in rpm_config :
916+ repo_name = repo ["package" ]
917+ version = repo .get ("version" )
918+ if version and version != "null" :
919+ repo_name = f"{ repo_name } _{ version } "
920+
921+ # Skip if already added due to version change
922+ if repo_name in repos_for_pub_dist_names :
923+ continue
924+
925+ # Check if repo is synced (has content) but missing publication or distribution
926+ # First verify the repo has been synced at least once (version > 0)
927+ repo_version = get_repo_version (repo_name , log )
928+ if repo_version == 0 :
929+ # Repo has never been synced, skip it
930+ log .debug (f"{ repo_name } has never been synced (version=0). Skipping pub/dist check." )
931+ continue
932+
933+ pub_exists = check_publication_exists (repo_name , log )
934+ dist_exists = check_distribution_exists (repo_name , log )
935+
936+ if not pub_exists or not dist_exists :
937+ log .info (f"{ repo_name } is synced (version={ repo_version } ) but missing publication={ not pub_exists } , distribution={ not dist_exists } . Including for pub/dist creation." )
938+ repo_copy = repo .copy ()
939+ repo_copy ["_version_changed" ] = False # No version change, just missing pub/dist
940+ repos_for_pub_dist .append (repo_copy )
941+ repos_for_pub_dist_names .add (repo_name )
942+
943+ # Determine if we should skip or process
944+ if repos_for_pub_dist :
945+ pub_dist_names = [r ["package" ] for r in repos_for_pub_dist ]
946+ log .info (f"Found { len (repos_for_pub_dist )} repo(s) needing publication/distribution: { pub_dist_names } " )
945947 return repos_for_pub_dist , False , ""
948+
949+ # All repos have publication and distribution - safe to skip
950+ log .info ("All synced repos have existing publication and distribution. Skipping pub/dist creation." )
951+ if actually_synced_repos :
952+ # Repos were synced but no metadata change
953+ synced_list = ", " .join (actually_synced_repos )
954+ skip_msg = f"Sync successful for { len (actually_synced_repos )} repo(s): { synced_list } . No metadata changes detected - existing publication/distribution retained"
946955 else :
947- # If no repos were actually synced, check for missing pub/dist (crash recovery)
948- if not actually_synced_repos :
949- log .info ("No repos were actually synced. Checking for missing publication/distribution." )
950- repos_missing_pub_dist = []
951- for repo in rpm_config :
952- repo_name = repo ["package" ]
953- version = repo .get ("version" )
954- if version and version != "null" :
955- repo_name = f"{ repo_name } _{ version } "
956-
957- # If resync_repos is a specific list, only check those repos
958- if resync_repos and resync_repos != "all" :
959- resync_list = resync_repos if isinstance (resync_repos , list ) else [r .strip () for r in resync_repos .split ("," )]
960- if repo_name not in resync_list :
961- continue
962-
963- pub_exists = check_publication_exists (repo_name , log )
964- dist_exists = check_distribution_exists (repo_name , log )
965-
966- if not pub_exists or not dist_exists :
967- log .info (f"{ repo_name } missing publication={ not pub_exists } , distribution={ not dist_exists } . Including for pub/dist creation." )
968- repo_copy = repo .copy ()
969- repo_copy ["_version_changed" ] = False
970- repos_missing_pub_dist .append (repo_copy )
971-
972- if repos_missing_pub_dist :
973- missing_names = [r ["package" ] for r in repos_missing_pub_dist ]
974- log .info (f"Found { len (repos_missing_pub_dist )} repo(s) missing publication/distribution: { missing_names } " )
975- return repos_missing_pub_dist , False , ""
976-
977- log .info ("All repos have existing publication and distribution. No updates required." )
978- return [], True , "All repositories already synced - no updates required"
979-
980- # Filter rpm_config to only include repos with version change
981- for repo in rpm_config :
982- repo_name = repo ["package" ]
983- version = repo .get ("version" )
984- if version and version != "null" :
985- repo_name = f"{ repo_name } _{ version } "
986- if repo_name in actually_synced_repos and repo_name in version_changed_repos :
987- repo_copy = repo .copy ()
988- repo_copy ["_version_changed" ] = True
989- repos_for_pub_dist .append (repo_copy )
990- return repos_for_pub_dist , False , ""
956+ # No repos were synced at all (already up to date)
957+ skip_msg = "All repositories already synced - no updates required"
958+ return [], True , skip_msg
991959
992960# ============================================================================
993961# AGGREGATED REPOS FUNCTIONS
0 commit comments