mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-10-10 04:03:04 +08:00
fix: add legacy subscriptions update fallback
This commit is contained in:
+10
-9
@@ -2,16 +2,17 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Runtime config
|
||||
config.yaml
|
||||
config.yaml.*
|
||||
# Local env
|
||||
.env
|
||||
|
||||
# Build / runtime artifacts
|
||||
resources/dist/
|
||||
resources/zip/*
|
||||
# Runtime
|
||||
runtime/
|
||||
|
||||
# 保留 dist.zip
|
||||
!resources/zip/dist.zip
|
||||
# Local dashboard unpacked files
|
||||
resources/dashboard/dist/
|
||||
|
||||
# 临时脚本
|
||||
# Keep packaged dashboard asset
|
||||
!resources/dashboard/dist.zip
|
||||
|
||||
# Local test scripts
|
||||
test.sh
|
||||
|
||||
@@ -197,6 +197,7 @@ Control 层负责把常用动作收口成可理解的命令和反馈。
|
||||
- `runtime/` 是唯一运行时容器
|
||||
- 后端可以是 `systemd`、`systemd-user` 或 `script`
|
||||
- 运行配置是 `runtime/config.yaml`
|
||||
- 订阅集合状态是 `runtime/subscriptions.yaml`(历史 `config/subscriptions.yaml` 仅用于兼容迁移)
|
||||
- 日志、状态、缓存和运行时产物都收敛到 runtime 体系
|
||||
|
||||
## 配置说明
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
active: default
|
||||
|
||||
sources:
|
||||
default:
|
||||
type: clash
|
||||
url: ""
|
||||
enabled: true
|
||||
+13
-3
@@ -57,7 +57,7 @@ clear_build_error_detail() {
|
||||
}
|
||||
|
||||
subscriptions_file() {
|
||||
echo "$CONFIG_DIR/subscriptions.yaml"
|
||||
echo "$RUNTIME_DIR/subscriptions.yaml"
|
||||
}
|
||||
|
||||
migrate_subscriptions_legacy_fields() {
|
||||
@@ -81,15 +81,25 @@ migrate_subscriptions_legacy_fields() {
|
||||
}
|
||||
|
||||
ensure_subscriptions_file() {
|
||||
local file
|
||||
local file legacy_file
|
||||
file="$(subscriptions_file)"
|
||||
legacy_file="$CONFIG_DIR/subscriptions.yaml"
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
migrate_subscriptions_legacy_fields "$file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
mkdir -p "$RUNTIME_DIR"
|
||||
|
||||
if [ -f "$legacy_file" ]; then
|
||||
mv -f "$legacy_file" "$file" 2>/dev/null || {
|
||||
cp -f "$legacy_file" "$file"
|
||||
rm -f "$legacy_file" 2>/dev/null || true
|
||||
}
|
||||
migrate_subscriptions_legacy_fields "$file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
cat > "$file" <<'EOF'
|
||||
active: default
|
||||
|
||||
@@ -34,6 +34,37 @@ git_has_local_changes() {
|
||||
[ -n "$(git -C "$PROJECT_DIR" status --porcelain --untracked-files=no 2>/dev/null)" ]
|
||||
}
|
||||
|
||||
git_has_changes_except_legacy_subscriptions() {
|
||||
git -C "$PROJECT_DIR" status --porcelain --untracked-files=no 2>/dev/null \
|
||||
| awk '{
|
||||
path=substr($0,4)
|
||||
if (path != "config/subscriptions.yaml") {
|
||||
found=1
|
||||
}
|
||||
}
|
||||
END { exit(found?0:1) }'
|
||||
}
|
||||
|
||||
handle_legacy_subscriptions_dirty_for_update() {
|
||||
local legacy_file runtime_file
|
||||
legacy_file="$CONFIG_DIR/subscriptions.yaml"
|
||||
runtime_file="$(subscriptions_file)"
|
||||
|
||||
git_has_local_changes || return 1
|
||||
git_has_changes_except_legacy_subscriptions && return 1
|
||||
|
||||
info "检测到历史路径 config/subscriptions.yaml 的本地改动,正在执行迁移兜底"
|
||||
|
||||
if [ -f "$legacy_file" ] && [ ! -f "$runtime_file" ]; then
|
||||
mkdir -p "$RUNTIME_DIR"
|
||||
cp -f "$legacy_file" "$runtime_file" 2>/dev/null || true
|
||||
migrate_subscriptions_legacy_fields "$runtime_file"
|
||||
fi
|
||||
|
||||
git -C "$PROJECT_DIR" checkout -- config/subscriptions.yaml >/dev/null 2>&1 || true
|
||||
return 0
|
||||
}
|
||||
|
||||
git_remote_name() {
|
||||
echo "${CLASH_GIT_REMOTE:-origin}"
|
||||
}
|
||||
@@ -167,6 +198,10 @@ update_project_code() {
|
||||
info "远程仓库:$remote_name"
|
||||
info "更新分支:$branch"
|
||||
|
||||
if [ "$force_mode" != "true" ]; then
|
||||
handle_legacy_subscriptions_dirty_for_update || true
|
||||
fi
|
||||
|
||||
if git_has_local_changes && [ "$force_mode" != "true" ]; then
|
||||
die "检测到本地有未提交改动,请先提交,或使用 clashctl update --force"
|
||||
fi
|
||||
|
||||
+4
-4
@@ -60,8 +60,8 @@ elif [ "$DEV_RESET" = "true" ]; then
|
||||
cache_restore_needed="true"
|
||||
fi
|
||||
|
||||
if [ -f "$CONFIG_DIR/subscriptions.yaml" ]; then
|
||||
cp -f "$CONFIG_DIR/subscriptions.yaml" "$subscriptions_backup_file" 2>/dev/null || true
|
||||
if [ -f "$RUNTIME_DIR/subscriptions.yaml" ]; then
|
||||
cp -f "$RUNTIME_DIR/subscriptions.yaml" "$subscriptions_backup_file" 2>/dev/null || true
|
||||
subscriptions_restore_needed="true"
|
||||
fi
|
||||
|
||||
@@ -74,8 +74,8 @@ elif [ "$DEV_RESET" = "true" ]; then
|
||||
fi
|
||||
|
||||
if [ "$subscriptions_restore_needed" = "true" ] && [ -f "$subscriptions_backup_file" ]; then
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
cp -f "$subscriptions_backup_file" "$CONFIG_DIR/subscriptions.yaml"
|
||||
mkdir -p "$RUNTIME_DIR"
|
||||
cp -f "$subscriptions_backup_file" "$RUNTIME_DIR/subscriptions.yaml"
|
||||
fi
|
||||
|
||||
rm -rf "$cache_backup_dir" 2>/dev/null || true
|
||||
|
||||
Reference in New Issue
Block a user