Skip to content

Commit 4589a4b

Browse files
feat(oma-mirror): add --timeout param for mirror speedtest cmd (#571)
* feat(oma-mirror): add `--timeout` param for mirror speedtest cmd * i18n: lint new UI strings * fix(oma-mirror): relocate unintended mirror-level global `--timeout` param --------- Co-authored-by: Mingcong Bai <[email protected]>
1 parent 89e5d3a commit 4589a4b

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

i18n/en-US/oma.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ clap-mirror-remove-names-help = Mirrors to be disabled/removed
402402
clap-mirror-sort-mirrors-help = Sort enabled mirror(s)
403403
clap-mirror-speedtest-help = Benchmark mirror(s)
404404
clap-mirror-speedtest-set-fastest-help = Set the fastest mirror as default
405+
clap-mirror-speedtest-timeout-help = Network timeout in seconds during speedtest (default: 120)
405406
clap-pick-package-help = Package to pick specific version for
406407
clap-rdepends-packages-help = Package(s) to query reverse dependency(ies) for
407408
clap-remove-packages-help = Package(s) to remove

i18n/zh-CN/oma.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ clap-mirror-remove-names-help = 要禁用(移除)的镜像源
391391
clap-mirror-sort-mirrors-help = 重新排序已启用的镜像源
392392
clap-mirror-speedtest-help = 测试镜像源性能
393393
clap-mirror-speedtest-set-fastest-help = 将测得最快的镜像源作为默认
394+
clap-mirror-speedtest-timeout-help = 设置测速时的网络超时时间(秒,默认:120)
394395
clap-pick-package-help = 要选择并安装特定版本的软件包
395396
clap-rdepends-packages-help = 要查询逆向依赖关系的软件包
396397
clap-remove-packages-help = 要移除的软件包

i18n/zh-TW/oma.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ clap-mirror-remove-names-help = 要禁用(移除)的鏡像源
373373
clap-mirror-sort-mirrors-help = 重新排序已啟用的鏡像源
374374
clap-mirror-speedtest-help = 測試鏡像源效能
375375
clap-mirror-speedtest-set-fastest-help = 將測得最快的鏡像源設為預設
376+
clap-mirror-speedtest-timeout-help = 設定測速時的網路超時時間(秒,預設:120)
376377
clap-mirror-set-help = 設定預設鏡像源
377378
clap-pick-package-help = 要選擇並安裝指定版本的軟體套件
378379
clap-rdepends-packages-help = 要查詢逆向依賴關係的軟體套件

src/subcommand/mirror.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ pub enum MirrorSubCmd {
176176
/// Also set fastest as mirror
177177
#[arg(long, help = fl!("clap-mirror-speedtest-set-fastest-help"))]
178178
set_fastest: bool,
179+
/// Network timeout in seconds (default: 120)
180+
#[arg(long, default_value = "120", help = fl!("clap-mirror-speedtest-timeout-help"))]
181+
timeout: f64,
179182
/// Do not refresh topics manifest.json file
180183
#[arg(long, help = fl!("clap-no-refresh-topics-help"))]
181184
no_refresh_topics: bool,
@@ -223,13 +226,15 @@ impl CliExecuter for CliMirror {
223226
#[cfg(feature = "aosc")]
224227
no_refresh_topics,
225228
no_refresh,
229+
timeout,
226230
} => speedtest(
227231
no_progress,
228232
set_fastest,
229233
!no_refresh_topics && !config.no_refresh_topics(),
230234
download_threads.unwrap_or_else(|| config.network_thread()),
231235
no_refresh,
232236
apt_options,
237+
timeout,
233238
),
234239
MirrorSubCmd::Add {
235240
names,
@@ -461,6 +466,7 @@ pub fn speedtest(
461466
network_threads: usize,
462467
no_refresh: bool,
463468
apt_options: Vec<String>,
469+
timeout: f64,
464470
) -> Result<i32, OutputError> {
465471
if set_fastest {
466472
root()?;
@@ -483,10 +489,9 @@ pub fn speedtest(
483489
} else {
484490
None
485491
};
486-
487492
let client = blocking::ClientBuilder::new()
488493
.user_agent(APP_USER_AGENT)
489-
.timeout(Duration::from_secs(120))
494+
.timeout(Duration::from_secs_f64(timeout))
490495
.build()?;
491496

492497
let mut score_map = HashMap::with_hasher(ahash::RandomState::new());

0 commit comments

Comments
 (0)