Skip to content

Commit b6a9101

Browse files
author
Mikachu2333
authored
修复某些系统which不存在的问题 (#271)
1 parent 795ed09 commit b6a9101

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/framework/core.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,29 +339,33 @@ query_program_exist (char *check_cmd, char *prog_name, int mode)
339339

340340

341341
/**
342-
* @brief 生成用于 '检测一个程序是否存在' 的命令,该内部函数由 chsrc_check_program() 家族调用
342+
* @brief 生成用于 检测一个程序是否存在 的命令,该内部函数由 chsrc_check_program() 家族调用
343343
*
344-
* 检查一个程序是否存在时,我们曾经使用 "调用 程序名 --version" 的方式 (即 cmd_to_check_program2()),
345-
* 但是该方式有三个问题:
346-
*
347-
* 1. 该程序得到直接执行,可能不太安全 (虽然基本不可能)
348-
* 2. 有一些程序启动速度太慢,即使只调用 --version,也依旧会花费许多时间,比如 mvn
349-
* 3. 有些程序并不支持 --version 选项 (虽然基本不可能)
350-
*
351-
* @note Unix 中,where 仅在 zsh 中可以使用,sh 和 Bash 中均无法使用,因为其并非二进制程序
352-
* 所以在 Unix 中,只能使用 which 或 whereis
344+
* @note
345+
* 1. Unix 中,where 仅在 zsh 中可以使用,sh 和 Bash 中均无法使用,因为其并非二进制程序
346+
* 2. 因部分linux系统没有 `which` 和 `whereis` 命令,使用 `command -v` 代替
353347
*/
354348
static char *
355349
cmd_to_check_program (char *prog_name)
356350
{
357-
char *check_tool = xy_on_windows ? "where " : "which ";
351+
char *check_tool = xy_on_windows ? "where " : "command -v ";
358352

359353
char *quiet_cmd = xy_str_to_quietcmd (xy_2strjoin (check_tool, prog_name));
360354

361355
return quiet_cmd;
362356
}
363357

358+
364359
XY_Deprecate_This("Use cmd_to_check_program() instead")
360+
/**
361+
* @brief 通过 `调用程序名 --version` 的方式检测程序是否存在
362+
*
363+
* @deprecated 因存在以下三个问题弃用:
364+
*
365+
* 1. 该程序得到直接执行,可能不太安全 (虽然基本不可能)
366+
* 2. 有一些程序启动速度太慢,即使只调用 --version,也依旧会花费许多时间,比如 mvn
367+
* 3. 有些程序并不支持 --version 选项 (虽然基本不可能)
368+
*/
365369
static char *
366370
cmd_to_check_program2 (char *prog_name)
367371
{

0 commit comments

Comments
 (0)