From 0373e8149eeecd02c4fc2ef66171ce63ed847d4f Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Mon, 4 Nov 2024 18:57:08 +0800 Subject: [PATCH] Implement `reset` for `Fedora` [GitHub #117 #111] --- include/source.h | 12 ++++++++---- src/recipe/os/YUM/Fedora-Linux.c | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/source.h b/include/source.h index 03c35f40..34534425 100644 --- a/include/source.h +++ b/include/source.h @@ -6,7 +6,7 @@ * Contributors : Shengwei Chen <414685209@qq.com> * | * Created On : <2023-08-29> - * Last Modified : <2024-10-09> + * Last Modified : <2024-11-04> * * 通用镜像站与换源信息 * ------------------------------------------------------------*/ @@ -192,8 +192,10 @@ typedef struct TargetInfo_t { #define def_target_inner_s(t) NULL, t##_setsrc, NULL, NULL -#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL +#define def_target_inner_sr(t) NULL, t##_setsrc, t##_resetsrc, NULL #define def_target_inner_sf(t) NULL, t##_setsrc, NULL, t##_feat +#define def_target_inner_srf(t) NULL, t##_setsrc, t##_resetsrc, t##_feat +#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL #define def_target_inner_gsr(t) t##_getsrc, t##_setsrc, t##_resetsrc, NULL #define def_target_inner_gsf(t) t##_getsrc, t##_setsrc, NULL, t##_feat #define def_target_inner_gsrf(t) t##_getsrc, t##_setsrc, t##_resetsrc, t##_feat @@ -202,9 +204,11 @@ typedef struct TargetInfo_t { // 大部分target还不支持reset,所以暂时先默认设置为NULL来过渡 #define def_target(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)} -#define def_target_gs(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)} +#define def_target_s(t) TargetInfo t##_target = {def_target_inner_s(t),def_target_sourcesn(t)} +#define def_target_sr(t) TargetInfo t##_target = {def_target_inner_sr(t),def_target_sourcesn(t)} #define def_target_sf(t) TargetInfo t##_target = {def_target_inner_sf(t),def_target_sourcesn(t)} +#define def_target_srf(t) TargetInfo t##_target = {def_target_inner_srf(t),def_target_sourcesn(t)} +#define def_target_gs(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)} #define def_target_gsr(t) TargetInfo t##_target = {def_target_inner_gsr(t),def_target_sourcesn(t)} #define def_target_gsf(t) TargetInfo t##_target = {def_target_inner_gsf(t),def_target_sourcesn(t)} #define def_target_gsrf(t) TargetInfo t##_target = {def_target_inner_gsrf(t),def_target_sourcesn(t)} -#define def_target_s(t) TargetInfo t##_target = {def_target_inner_s(t),def_target_sourcesn(t)} diff --git a/src/recipe/os/YUM/Fedora-Linux.c b/src/recipe/os/YUM/Fedora-Linux.c index 19262298..520fa3f2 100644 --- a/src/recipe/os/YUM/Fedora-Linux.c +++ b/src/recipe/os/YUM/Fedora-Linux.c @@ -2,8 +2,9 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Authors : Heng Guo <2085471348@qq.com> - * Contributors : Aoran Zeng * | happy game + * Contributors : Aoran Zeng + * | * Created On : <2023-09-26> * Last Modified : <2024-11-04> * @@ -15,7 +16,7 @@ */ static SourceInfo os_fedora_sources[] = { - {&Upstream, "http://download.example/pub/fedora/linux"}, + {&Upstream, "http://download.example/pub/fedora/linux"}, {&Ali, "https://mirrors.aliyun.com/fedora"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/fedora"}, {&Ustc, "https://mirrors.ustc.edu.cn/fedora"}, @@ -36,6 +37,8 @@ def_sources_n(os_fedora); void os_fedora_setsrc (char *option) { + char *setsrc_type = xy_streql (option, SetsrcType_Reset) ? SetsrcType_Reset : SetsrcType_Auto; + chsrc_ensure_root (); chsrc_yield_source_and_confirm (os_fedora); @@ -45,7 +48,7 @@ os_fedora_setsrc (char *option) chsrc_backup ("/etc/yum.repos.d/fedora.repo"); chsrc_backup ("/etc/yum.repos.d/fedora-updates.repo"); - // 取消注释 baseurl + // 取消对 baseurl 的注释 char* cmd = xy_strjoin (5, "sed ", "-i 's|^#baseurl=|baseurl=", "|g' ", @@ -53,8 +56,9 @@ os_fedora_setsrc (char *option) "/etc/yum.repos.d/fedora-updates.repo"); chsrc_run (cmd, RunOpt_Default); - // fedora的换源涉及 /etc/yum.repos.d/fedora.repo和 /etc/yum.repos.d/fedora-updates.repo - // 需要替换 baseurl=source.url/releases/... 和 baseurl=source.url/releases/... + // 替换 + // (1) baseurl=<>/releases/... + // (2) baseurl=<>/updates/... cmd = xy_strjoin (7, "sed ", "-i -E 's!^baseurl=.*?/(releases|updates)/!baseurl=", source.url, @@ -69,10 +73,17 @@ os_fedora_setsrc (char *option) chsrc_log2 ("(2) /etc/yum.repos.d/fedora-updates.repo"); chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line); - chsrc_conclude (&source, SetsrcType_Auto); + + chsrc_conclude (&source, setsrc_type); } +void +os_fedora_resetsrc (char *option) +{ + os_fedora_setsrc (SetsrcType_Reset); +} + FeatInfo os_fedora_feat (char *option) @@ -80,14 +91,13 @@ os_fedora_feat (char *option) FeatInfo f = {0}; f.can_get = false; - f.can_reset = false; + f.can_reset = true; f.cap_locally = CanNot; - f.can_english = true; + f.can_english = false; f.can_user_define = true; return f; } def_target_sf(os_fedora); -