From c91e4935c392790ee1b403f0f499d4b7f0940fec Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Thu, 20 Nov 2025 19:04:15 +0800 Subject: [PATCH] fix: enhance config file checks to prevent errors on missing or empty files Add checks using `-s` flag to verify config.json existence and non-emptiness before processing passwords, avoiding potential script failures when the file is absent or zero-length, improving robustness. --- bin/create_config.sh | 2 +- bin/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/create_config.sh b/bin/create_config.sh index 3fc9f12..ccaca32 100644 --- a/bin/create_config.sh +++ b/bin/create_config.sh @@ -73,7 +73,7 @@ create_self_tls_config() { create_config(){ local script_dir=$(cd "$(dirname "$0")"; pwd) local config_password=$(jq -r '.auth.password' "$script_dir/../config.json") - if [ "$config_password" != "你的密码" ]; then + if [ -s "$script_dir/../config.json" ] && [ "$config_password" != "你的密码" ]; then local regenerate read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then diff --git a/bin/run.sh b/bin/run.sh index 2173f60..7d2fb03 100644 --- a/bin/run.sh +++ b/bin/run.sh @@ -15,7 +15,7 @@ run() { # 如果配置没有创建 local password=$(jq -r '.auth.password' "$config_dir/config.json") - if [ "$password" = "你的密码" ]; then + if [ ! -s "$config_dir/config.json" ] || [ "$password" = "你的密码" ]; then bash "$script_dir/create_config.sh" # 创建配置 fi