diff --git a/lib/xy.h b/lib/xy.h index bc5d753..8b1874b 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -624,7 +624,8 @@ xy_run_iter (const char *cmd, unsigned long n, void (*iter_func) (const char * { if (NULL == fgets (buf, size, stream)) break; - ret = buf; + /* 存在换行的总是会把换行符读出来,删掉 */ + ret = xy_str_delete_suffix (buf, "\n"); count += 1; if (n == count) break; diff --git a/src/framework/core.c b/src/framework/core.c index 2b205d8..f3c46d1 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -472,13 +472,15 @@ measure_speed_for_url (void *url) time_sec = "8"; - /* 现在我们切换至跳转后的链接来测速,不再使用下述判断 - if (xy_str_start_with(url, "https://registry.npmmirror")) - { - // 这里 npmmirror 跳转非常慢,需要1~3秒,所以我们给它留够至少8秒测速时间,否则非常不准 - time_sec = "10"; - } - */ + /** + * 现在我们切换至跳转后的链接来测速,不再使用下述判断 + * + * if (xy_str_start_with(url, "https://registry.npmmirror")) + * { + * // 这里 npmmirror 跳转非常慢,需要1~3秒,所以我们给它留够至少8秒测速时间,否则非常不准 + * time_sec = "10"; + * } + */ char *ipv6 = ""; // 默认不启用 @@ -487,11 +489,11 @@ measure_speed_for_url (void *url) ipv6 = "--ipv6"; } - char *os_devnull = xy_os_devnull; - // 我们用 —L,因为Ruby China源会跳转到其他地方 - // npmmirror 也会跳转 + /** + * @note 我们用 —L,因为部分链接会跳转到其他地方,比如: RubyChina, npmmirror + */ char *curl_cmd = xy_strjoin (8, "curl -qsL ", ipv6, " -o ", os_devnull, " -w \"%{http_code} %{speed_download}\" -m", time_sec, @@ -501,9 +503,6 @@ measure_speed_for_url (void *url) char *curl_buf = xy_run (curl_cmd, 0); - // 如果尾部有换行,删除 - curl_buf = xy_str_strip (curl_buf); - return curl_buf; } diff --git a/src/recipe/lang/Python/Rye.c b/src/recipe/lang/Python/Rye.c index bb6687e..9957570 100644 --- a/src/recipe/lang/Python/Rye.c +++ b/src/recipe/lang/Python/Rye.c @@ -13,7 +13,7 @@ char * pl_python_find_rye_config () { char *buf = xy_run ("rye config --show-path", 0); - char *rye_config = xy_normalize_path (xy_str_strip (buf)); + char *rye_config = xy_normalize_path (buf); return rye_config; } diff --git a/src/recipe/lang/Ruby.c b/src/recipe/lang/Ruby.c index 8f77f09..d0f2bf2 100644 --- a/src/recipe/lang/Ruby.c +++ b/src/recipe/lang/Ruby.c @@ -56,8 +56,7 @@ pl_ruby_remove_gem_source (const char *source) char *cmd = NULL; if (is_url (source)) { - cmd = xy_str_delete_suffix (source, "\n"); - cmd = xy_2strjoin ("gem sources -r ", cmd); + cmd = xy_2strjoin ("gem sources -r ", source); chsrc_run (cmd, RunOpt_Default); } } diff --git a/src/recipe/os/APT/common.h b/src/recipe/os/APT/common.h index b1179b7..28aa8e7 100644 --- a/src/recipe/os/APT/common.h +++ b/src/recipe/os/APT/common.h @@ -60,13 +60,10 @@ ensure_apt_sourcelist (int debian_type) chsrc_note2 (msg); } - // 反向引用需要escape一下 + /* 反向引用需要escape */ char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_OS_RELEASE, 0); - codename = xy_str_delete_suffix (codename, "\n"); char *version_id = xy_run ("sed -nr 's/VERSION_ID=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); - version_id = xy_str_delete_suffix (codename, "\n"); - double version = atof (version_id); diff --git a/src/recipe/os/YUM/Rocky-Linux.c b/src/recipe/os/YUM/Rocky-Linux.c index 01a4b56..8ca433c 100644 --- a/src/recipe/os/YUM/Rocky-Linux.c +++ b/src/recipe/os/YUM/Rocky-Linux.c @@ -28,7 +28,7 @@ def_sources_n(os_rockylinux); /** - * 参考: https://help.mirrors.cernet.edu.cn/rocky/ + * @consult https://help.mirrors.cernet.edu.cn/rocky/ */ void os_rockylinux_setsrc (char *option) @@ -37,9 +37,7 @@ os_rockylinux_setsrc (char *option) chsrc_yield_source_and_confirm (os_rockylinux); - char *version_str = xy_run ("sed -nr 's/ROCKY_SUPPORT_PRODUCT_VERSION=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); - version_str = xy_str_delete_suffix (version_str, "\n"); double version = atof (version_str); char *cmd = NULL; diff --git a/src/recipe/os/pacman/Arch-Linux.c b/src/recipe/os/pacman/Arch-Linux.c index c640593..5200ed6 100644 --- a/src/recipe/os/pacman/Arch-Linux.c +++ b/src/recipe/os/pacman/Arch-Linux.c @@ -28,7 +28,7 @@ static Source_t os_arch_sources[] = /** * @update 2024-07-03 - * @note 根据 GitHub:@zheng7fu2 建议,拆分 archlinuxcn 出来 + * @note 根据 @zheng7fu2 建议,拆分 archlinuxcn 出来 */ os_archlinuxcn_sources[] = { @@ -53,9 +53,9 @@ os_arch_getsrc (char *option) } /** - * 参考: - * 1. https://mirrors.tuna.tsinghua.edu.cn/help/archlinux/ - * 2. https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxarm/ + * @consult + * 1. https://mirrors.tuna.tsinghua.edu.cn/help/archlinux/ + * 2. https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxarm/ */ void os_arch_setsrc (char *option) @@ -104,7 +104,7 @@ os_archlinuxcn_getsrc (char *option) } /** - * 参考 https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/ + * @consult https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/ */ void os_archlinuxcn_setsrc (char *option) diff --git a/src/recipe/ware/Docker-Hub.c b/src/recipe/ware/Docker-Hub.c index f688d8d..c6781ed 100644 --- a/src/recipe/ware/Docker-Hub.c +++ b/src/recipe/ware/Docker-Hub.c @@ -98,7 +98,7 @@ wr_dockerhub_setsrc (char *option) "\")' ", WARE_DockerHub_SourceConfig); char *ret = xy_run(cmd, 0); - if (ret && !xy_streql(ret, "null\n")) + if (ret && !xy_streql(ret, "null")) { chsrc_note2 ("已存在源,无需重复添加"); }