Output clearly when skip

[GitHub #122]
This commit is contained in:
Aoran Zeng
2024-11-21 11:21:13 +08:00
parent 9e6ff663f9
commit bba1df37f8
6 changed files with 219 additions and 109 deletions

View File

@@ -383,6 +383,8 @@ query_mirror_exist (SourceInfo *sources, size_t size, char *target, char *input)
/**
* 该函数来自 oh-my-mirrorz.py由 @ccmywish 翻译为C语言但功劳和版权属于原作者
*
* @param speed 单位为Byte/s
*/
char *
to_human_readable_speed (double speed)
@@ -490,7 +492,7 @@ measure_speed_for_url (void *url)
/**
* @return 返回速度speed
* @return 返回速度speed,单位为 Byte/s
*/
double
parse_and_say_curl_result (char *curl_buf)
@@ -538,13 +540,13 @@ get_max_ele_idx_in_dbl_ary (double *array, int size)
/**
* @param sources 所有待测源
* @param size 待测源的数量
* @param[out] speed_records 速度值记录
* @param[out] speed_records 速度值记录单位为Byte/s
*/
void
measure_speed_for_every_source (SourceInfo sources[], int size, double speed_records[])
{
bool get_measured[size]; /* 是否测速 */
int get_measured_n = 0; /* 测速了几个 */
bool get_measured[size]; /* 是否真正执行了测速 */
int get_measured_n = 0; /* 测速了几个 */
char *measure_msgs[size];
double speed = 0.0;
@@ -552,35 +554,63 @@ measure_speed_for_every_source (SourceInfo sources[], int size, double speed_rec
for (int i=0; i<size; i++)
{
SourceInfo src = sources[i];
const char *url = src.mirror->bigfile_url;
if (NULL==url)
const SpeedMeasureInfo smi = src.mirror->smi;
bool skip = smi.skip;
const char *url = smi.url;
if (!skip && NULL==url)
// 这种情况应当被视为bug但是我们目前还是软处理
{
char *msg1 = CliOpt_InEnglish ? "Maintainers don't offer " : "维护者未提供 ";
char *msg2 = CliOpt_InEnglish ? " mirror site's speed measure link, so skip it" : " 镜像站测速链接,跳过该站点";
chsrc_warn (xy_strjoin (3, msg1, src.mirror->code, msg2));
speed = 0;
speed_records[i] = speed;
get_measured[i] = false;
measure_msgs[i] = NULL;
}
if (skip)
{
if (xy_streql ("upstream", src.mirror->code))
{
// 上游源不测速但不置0因为要避免这种情况: 可能其他镜像站测速都为0最后反而选择了该 upstream
speed = -999;
speed = -1024*1024*1024;
}
else if (xy_streql ("user", src.mirror->code))
{
// 代码不会执行至此
speed = 1024*1024*1024;
}
else
{
char *msg1 = CliOpt_InEnglish ? "Dev team doesn't offer " : "开发者未提供 ";
char *msg2 = CliOpt_InEnglish ? " mirror site's speed measure link, so skip it" : " 镜像站测速链接,跳过该站点";
chsrc_warn (xy_strjoin (3, msg1, src.mirror->code, msg2));
speed = 0;
// 什么情况?
speed = -1;
}
speed_records[i] = speed;
get_measured[i] = false;
measure_msgs[i] = NULL;
speed_records[i] = speed;
const char *msg = CliOpt_InEnglish ? src.mirror->abbr : src.mirror->name;
const char *skip_reason = CliOpt_InEnglish ? smi.skip_reason_EN : smi.skip_reason_CN;
if (NULL==skip_reason)
{
skip_reason = CliOpt_InEnglish ? "SKIP for no reason" : "无理由跳过";
}
measure_msgs[i] = xy_strjoin (4, " x ", msg, " ", yellow(skip_reason));
printf ("%s\n", measure_msgs[i]);
}
else
{
const char *msg = CliOpt_InEnglish ? src.mirror->abbr : src.mirror->name;
measure_msgs[i] = xy_strjoin (3, " - ", msg, " ... ");
printf ("%s", measure_msgs[i]);
fflush (stdout);
char *url_ = xy_strdup (url);
char *curl_result = measure_speed_for_url (url_);
double speed = parse_and_say_curl_result (curl_result);
speed_records[i] = speed;

View File

@@ -10,11 +10,15 @@
* ------------------------------------------------------------*/
static MirrorSite
GoProxyCN = {"goproxy.cn", "Goproxy.cn", "Goproxy.cn (七牛云)", "https://goproxy.cn/",
"https://goproxy.cn/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"}, // 30 MB
GoProxyCN = {
"goproxy.cn", "Goproxy.cn", "Goproxy.cn (七牛云)", "https://goproxy.cn/",
{false, NULL, NULL, "https://goproxy.cn/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"} // 30 MB
},
GoProxyIO = {"goproxy.io", "GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/",
"https://goproxy.io/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"}; // 30 MB
GoProxyIO = {
"goproxy.io", "GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/",
{false, NULL, NULL, "https://goproxy.io/github.com/aws/aws-sdk-go/@v/v1.45.2.zip"} // 30 MB
};
/**

View File

@@ -9,9 +9,11 @@
* ------------------------------------------------------------*/
static MirrorSite
NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/",
// 注意,这个是跳转后的地址,不确定未来会不会改变
"https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"}; // 29MB
NpmMirror = {
"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/",
// 注意,下面这个是跳转后的地址,不确定未来会不会改变
{false, NULL, NULL, "https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"} // 29MB
};
/**

View File

@@ -4,12 +4,14 @@
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-08-29>
* Last Modified : <2024-11-08>
* Last Modified : <2024-11-21>
* ------------------------------------------------------------*/
static MirrorSite
RubyChina = {"rubychina", "RubyChina", "Ruby China 社区", "https://gems.ruby-china.com/",
"https://gems.ruby-china.com/rubygems/gems/nokogiri-1.15.0-java.gem"}; // 9.9 MB
RubyChina = {
"rubychina", "RubyChina", "Ruby China 社区", "https://gems.ruby-china.com/",
{false, NULL, NULL, "https://gems.ruby-china.com/rubygems/gems/nokogiri-1.15.0-java.gem"} // 9.9 MB
};
/**
* @update 2024-09-04

View File

@@ -10,15 +10,22 @@
* ------------------------------------------------------------*/
static MirrorSite
// 没有找到 DaoCloud 合适的下载链接,先随便给一个,以规避 chsrc 自动测速时所有 dockerhub 镜像站都没有测速链接带来的 bug
DaoCloud = {"daocloud", "DaoCloud","上海道客网络科技有限公司", "https://www.daocloud.io/",
"https://qiniu-download-public.daocloud.io/DaoCloud_Enterprise/dce5/offline-community-v0.18.0-amd64.tar"},
DaoCloud = {
"daocloud", "DaoCloud","上海道客网络科技有限公司", "https://www.daocloud.io/",
// 没有找到 DaoCloud 合适的下载链接,先随便给一个,以规避 chsrc 自动测速时所有 dockerhub 镜像站都没有测速链接带来的 bug
{false, NULL, NULL, "https://qiniu-download-public.daocloud.io/DaoCloud_Enterprise/dce5/offline-community-v0.18.0-amd64.tar"}
},
Fit2Cloud = {"fit2cloud", "FIT2CLOUD", "杭州飞致云信息科技有限公司", "https://www.fit2cloud.com/", NULL},
Fit2Cloud = {
"fit2cloud", "FIT2CLOUD", "杭州飞致云信息科技有限公司", "https://www.fit2cloud.com/",
{true, NULL, NULL, NULL}
},
Huecker = {"huecker", "(Russia) Huecker", "俄罗斯 Huecker.io", "https://huecker.io/",
// 同 DaoCloud没有合适的下载链接先随便给一个以避免 bug
"https://huecker.io/en/use.html"};
Huecker = {
"huecker", "(Russia) Huecker", "俄罗斯 Huecker.io", "https://huecker.io/",
// 同 DaoCloud没有合适的下载链接先随便给一个以避免 bug
{false, NULL, NULL, "https://huecker.io/en/use.html"}
};
/**
* @update 2024-07-24