1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 16:45:07 +00:00

fix: dedupe cleanup previews by filesystem identity

This commit is contained in:
Tw93
2026-03-19 00:32:28 +08:00
parent 03db800709
commit 821a824d81
5 changed files with 106 additions and 2 deletions

View File

@@ -117,6 +117,8 @@ project_cache_has_indicators() {
# Discover candidate project roots without scanning the whole home directory.
discover_project_cache_roots() {
local -a roots=()
local -a unique_roots=()
local -a seen_identities=()
local root
for root in "${MOLE_PURGE_DEFAULT_SEARCH_PATHS[@]}"; do
@@ -147,7 +149,18 @@ discover_project_cache_roots() {
[[ ${#roots[@]} -eq 0 ]] && return 0
printf '%s\n' "${roots[@]}" | LC_ALL=C sort -u
for root in "${roots[@]}"; do
local identity
identity=$(mole_path_identity "$root")
if [[ ${#seen_identities[@]} -gt 0 ]] && mole_identity_in_list "$identity" "${seen_identities[@]}"; then
continue
fi
seen_identities+=("$identity")
unique_roots+=("$root")
done
[[ ${#unique_roots[@]} -gt 0 ]] && printf '%s\n' "${unique_roots[@]}"
}
# Scan a project root for supported build caches while pruning heavy subtrees.

View File

@@ -27,6 +27,45 @@ if [[ -f "$_MOLE_CORE_DIR/sudo.sh" ]]; then
source "$_MOLE_CORE_DIR/sudo.sh"
fi
# Normalize a path for comparisons while preserving root.
mole_normalize_path() {
local path="$1"
local normalized="${path%/}"
[[ -n "$normalized" ]] && printf '%s\n' "$normalized" || printf '%s\n' "$path"
}
# Return a stable identity for an existing path. Prefer dev+inode so aliased
# paths on case-insensitive filesystems or symlinks collapse to one identity.
mole_path_identity() {
local path="$1"
local normalized
normalized=$(mole_normalize_path "$path")
if [[ -e "$normalized" || -L "$normalized" ]]; then
if command -v stat > /dev/null 2>&1; then
local fs_id=""
fs_id=$(stat -L -f '%d:%i' "$normalized" 2> /dev/null || stat -f '%d:%i' "$normalized" 2> /dev/null || true)
if [[ "$fs_id" =~ ^[0-9]+:[0-9]+$ ]]; then
printf 'inode:%s\n' "$fs_id"
return 0
fi
fi
fi
printf 'path:%s\n' "$normalized"
}
mole_identity_in_list() {
local needle="$1"
shift
local existing
for existing in "$@"; do
[[ "$existing" == "$needle" ]] && return 0
done
return 1
}
# Update via Homebrew
update_via_homebrew() {
local current_version="$1"