From 068d91329fa1e9b1c661a7b3f6cc8ac6d20b48a8 Mon Sep 17 00:00:00 2001 From: shenmo Date: Mon, 13 Jul 2026 21:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=89=E6=97=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=9C=B0=E8=B7=B3=E8=BF=87=E8=A6=86=E7=9B=96=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apm-dummy/DEBIAN/control | 2 +- apm-dummy/usr/bin/amber-pm-base-overrider | 42 +++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/apm-dummy/DEBIAN/control b/apm-dummy/DEBIAN/control index 2a035d0..925b095 100755 --- a/apm-dummy/DEBIAN/control +++ b/apm-dummy/DEBIAN/control @@ -1,5 +1,5 @@ Package: apm -Version: 1.1.6-1 +Version: 1.1.6-2 Maintainer: shenmo Priority: optional Section: utils diff --git a/apm-dummy/usr/bin/amber-pm-base-overrider b/apm-dummy/usr/bin/amber-pm-base-overrider index b8094e6..8c59f28 100755 --- a/apm-dummy/usr/bin/amber-pm-base-overrider +++ b/apm-dummy/usr/bin/amber-pm-base-overrider @@ -141,16 +141,44 @@ for pkg_dir in "$APM_BASE_DIR"/*/; do fi # 检查是否有文件需要更新(比较源文件和目标文件) - NEED_UPDATE=false - while IFS= read -r -d '' file; do - rel_path="${file#$OVERRIDE_SOURCE/}" - target_file="$target_dir/$rel_path" - # 如果目标文件不存在或源文件更新,则需要更新 - if [ ! -e "$target_file" ] || [ "$file" -nt "$target_file" ]; then +NEED_UPDATE=false +while IFS= read -r -d '' file; do + rel_path="${file#$OVERRIDE_SOURCE/}" + target_file="$target_dir/$rel_path" + + # 1. 目标文件不存在 ⇒ 需要更新 + if [ ! -e "$target_file" ]; then + NEED_UPDATE=true + break + fi + + # 2. 先比较文件大小(快速排除明显不同) + if [ "$(stat -c%s "$file")" -ne "$(stat -c%s "$target_file")" ]; then + NEED_UPDATE=true + break + fi + + # 3. 再比较哈希值(选择系统中可用的哈希工具) + if command -v md5sum >/dev/null 2>&1; then + hash_cmd="md5sum" + elif command -v sha256sum >/dev/null 2>&1; then + hash_cmd="sha256sum" + else + # 若两者都不可用,退化为直接二进制比较(较慢,但确保正确) + if ! cmp -s "$file" "$target_file"; then NEED_UPDATE=true break fi - done < <(find "$OVERRIDE_SOURCE" -type f -print0 2>/dev/null) + continue + fi + + source_hash=$($hash_cmd "$file" | awk '{print $1}') + target_hash=$($hash_cmd "$target_file" | awk '{print $1}') + if [ "$source_hash" != "$target_hash" ]; then + NEED_UPDATE=true + break + fi +done < <(find "$OVERRIDE_SOURCE" -type f -print0 2>/dev/null) # 如果没有需要更新的文件,跳过 if [ "$NEED_UPDATE" = false ]; then