Skip to content

Commit 4c6ca7d

Browse files
committed
Use 'old source list' macro
[GitHub #185]
1 parent 24af8eb commit 4c6ca7d

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/recipe/os/APT/Debian.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ os_debian_getsrc (char *option)
4747
return;
4848
}
4949

50-
if (chsrc_check_file (OS_Apt_SourceList))
50+
if (chsrc_check_file (OS_Debian_old_SourceList))
5151
{
52-
chsrc_view_file (OS_Apt_SourceList);
52+
chsrc_view_file (OS_Debian_old_SourceList);
5353
return;
5454
}
5555

56-
chsrc_error2 ("缺少源配置文件!但仍可直接通过 chsrc set debian 来添加使用新的源");
56+
char *msg = CliOpt_InEnglish ? "Source list file missing! However, you can still run `chsrc set debian` to add and use new sources"
57+
: "缺少源配置文件!但仍可直接通过 chsrc set debian 来添加使用新的源";
58+
chsrc_error2 (msg);
5759
return;
5860
}
5961

@@ -62,7 +64,7 @@ static bool
6264
os_debian_does_old_sourcelist_use_cdrom (void)
6365
{
6466
/* 我们只检查旧版sourcelist,因为 common.h 中的填充只支持旧版 */
65-
char *cmd = xy_2strjoin ("grep -q '^deb cdrom:' ", OS_Apt_SourceList);
67+
char *cmd = xy_2strjoin ("grep -q '^deb cdrom:' ", OS_Debian_old_SourceList);
6668
int ret = system (cmd);
6769
bool use_cdrom = ret == 0;
6870

@@ -112,7 +114,7 @@ os_debian_setsrc (char *option)
112114
chsrc_note2 ("将基于旧格式(非DEB822)换源");
113115

114116
/* Docker环境下,Debian镜像可能不存在该文件 */
115-
bool sourcelist_exist = ensure_apt_sourcelist (OS_Is_Debian_Literally);
117+
bool sourcelist_exist = ensure_debian_or_ubuntu_old_sourcelist (OS_Is_Debian_Literally);
116118

117119
/**
118120
* 处理带有CDROM源的sourcelist
@@ -128,7 +130,7 @@ os_debian_setsrc (char *option)
128130
system ("rm " OS_Debian_old_SourceList);
129131
chsrc_warn2 ("旧版源配置文件中使用了 CDROM 源,已删除(但备份)该配置文件,重新配置");
130132
/* 现在的情况是:系统中已经没有配置文件了 */
131-
sourcelist_exist = ensure_apt_sourcelist (OS_Is_Debian_Literally);
133+
sourcelist_exist = ensure_debian_or_ubuntu_old_sourcelist (OS_Is_Debian_Literally);
132134
}
133135
}
134136

src/recipe/os/APT/Ubuntu.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Contributors : Zhao <[email protected]>
77
* |
88
* Created On : <2023-08-30>
9-
* Last Modified : <2024-12-18>
9+
* Last Modified : <2025-03-25>
1010
* ------------------------------------------------------------*/
1111

1212
static SourceProvider_t os_ubuntu_upstream =
@@ -46,13 +46,13 @@ os_ubuntu_getsrc (char *option)
4646
return;
4747
}
4848

49-
if (chsrc_check_file (OS_Apt_SourceList))
49+
if (chsrc_check_file (OS_Ubuntu_old_SourceList))
5050
{
51-
chsrc_view_file (OS_Apt_SourceList);
51+
chsrc_view_file (OS_Ubuntu_old_SourceList);
5252
return;
5353
}
5454

55-
char *msg = CliOpt_InEnglish ? "Source config file missing! However, you can still run `chsrc set ubuntu` to add and use new sources"
55+
char *msg = CliOpt_InEnglish ? "Source list file missing! However, you can still run `chsrc set ubuntu` to add and use new sources"
5656
: "缺少源配置文件!但仍可直接通过 chsrc set ubuntu 来添加使用新的源";
5757
chsrc_error2 (msg);
5858
return;
@@ -98,31 +98,33 @@ os_ubuntu_setsrc (char *option)
9898
if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822))
9999
{
100100
char *msg = CliOpt_InEnglish ? "Will change source based on new format"
101-
: "将基于新格式换源";
101+
: "将基于新格式(DEB822)换源";
102102
chsrc_note2 (msg);
103103
os_ubuntu_setsrc_for_deb822 (option);
104104
return;
105105
}
106106

107-
bool sourcelist_exist = ensure_apt_sourcelist (OS_Is_Ubuntu);
107+
chsrc_note2 ("将基于旧格式(非DEB822)换源");
108+
109+
bool sourcelist_exist = ensure_debian_or_ubuntu_old_sourcelist (OS_Is_Ubuntu);
108110

109111
chsrc_yield_source_and_confirm (os_ubuntu);
110112

111-
// 不存在的时候,用的是我们生成的无效文件,不要备份
113+
/* 不存在的时候,用的是我们生成的无效文件,不要备份 */
112114
if (sourcelist_exist)
113115
{
114-
chsrc_backup (OS_Apt_SourceList);
116+
chsrc_backup (OS_Ubuntu_old_SourceList);
115117
}
116118

117-
char *arch = chsrc_get_cpuarch ();
119+
char *arch = chsrc_get_cpuarch();
118120
char *cmd = NULL;
119121
if (0==strncmp (arch, "x86_64", 6))
120122
{
121-
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Apt_SourceList);
123+
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_old_SourceList);
122124
}
123125
else
124126
{
125-
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Apt_SourceList);
127+
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_old_SourceList);
126128
}
127129

128130
chsrc_run (cmd, RunOpt_Default);

src/recipe/os/APT/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @return 文件是否存在
5353
*/
5454
bool
55-
ensure_apt_sourcelist (int debian_type)
55+
ensure_debian_or_ubuntu_old_sourcelist (int debian_type)
5656
{
5757
bool exist = chsrc_check_file (OS_Apt_SourceList);
5858

0 commit comments

Comments
 (0)