mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:49:41 +00:00
feat: harden user file handling and gate LaunchServices rebuild (#159)
- add ensure_user_dir/ensure_user_file helpers in lib/core/base.sh, including sudo-aware ownership correction under the invoking user’s home - use the helpers across clean/optimize/purge/uninstall/whitelist to create cache and export files safely (no naked mkdir/touch), including log files and dry-run exports - ensure purge stats/count files and update message caches are pre-created with safe permissions - add Darwin version helpers and skip LaunchServices/dyld rebuild on macOS 15+, keeping the existing corruption protection for earlier versions - guard brew cache timestamp writes and TCC permission flags with safe file creation to avoid root-owned artifacts
This commit is contained in:
@@ -159,6 +159,7 @@ start_section() {
|
||||
|
||||
# Write section header to export list in dry-run mode
|
||||
if [[ "$DRY_RUN" == "true" ]]; then
|
||||
ensure_user_file "$EXPORT_LIST_FILE"
|
||||
echo "" >> "$EXPORT_LIST_FILE"
|
||||
echo "=== $1 ===" >> "$EXPORT_LIST_FILE"
|
||||
fi
|
||||
@@ -452,7 +453,7 @@ start_cleanup() {
|
||||
SYSTEM_CLEAN=false
|
||||
|
||||
# Initialize export list file
|
||||
mkdir -p "$(dirname "$EXPORT_LIST_FILE")"
|
||||
ensure_user_file "$EXPORT_LIST_FILE"
|
||||
cat > "$EXPORT_LIST_FILE" << EOF
|
||||
# Mole Cleanup Preview - $(date '+%Y-%m-%d %H:%M:%S')
|
||||
#
|
||||
|
||||
@@ -200,7 +200,7 @@ cleanup_path() {
|
||||
ensure_directory() {
|
||||
local raw_path="$1"
|
||||
local expanded_path="${raw_path/#\~/$HOME}"
|
||||
mkdir -p "$expanded_path" > /dev/null 2>&1 || true
|
||||
ensure_user_dir "$expanded_path"
|
||||
}
|
||||
|
||||
count_local_snapshots() {
|
||||
|
||||
@@ -47,7 +47,9 @@ start_purge() {
|
||||
|
||||
# Initialize stats file in user cache directory
|
||||
local stats_dir="${XDG_CACHE_HOME:-$HOME/.cache}/mole"
|
||||
mkdir -p "$stats_dir"
|
||||
ensure_user_dir "$stats_dir"
|
||||
ensure_user_file "$stats_dir/purge_stats"
|
||||
ensure_user_file "$stats_dir/purge_count"
|
||||
echo "0" > "$stats_dir/purge_stats"
|
||||
echo "0" > "$stats_dir/purge_count"
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ scan_applications() {
|
||||
local cache_ttl=86400 # 24 hours
|
||||
local force_rescan="${1:-false}"
|
||||
|
||||
mkdir -p "$cache_dir" 2> /dev/null
|
||||
ensure_user_dir "$cache_dir"
|
||||
|
||||
# Check if cache exists and is fresh
|
||||
if [[ $force_rescan == false && -f "$cache_file" ]]; then
|
||||
@@ -310,6 +310,7 @@ scan_applications() {
|
||||
fi
|
||||
fi
|
||||
|
||||
ensure_user_file "$cache_file"
|
||||
cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true
|
||||
|
||||
if [[ -f "${temp_file}.sorted" ]]; then
|
||||
|
||||
@@ -75,7 +75,7 @@ scan_applications() {
|
||||
local cache_ttl=86400 # 24 hours
|
||||
local force_rescan="${1:-false}"
|
||||
|
||||
mkdir -p "$cache_dir" 2> /dev/null
|
||||
ensure_user_dir "$cache_dir"
|
||||
|
||||
# Check if cache exists and is fresh
|
||||
if [[ $force_rescan == false && -f "$cache_file" ]]; then
|
||||
@@ -344,6 +344,7 @@ scan_applications() {
|
||||
fi
|
||||
|
||||
# Save to cache (simplified - no metadata)
|
||||
ensure_user_file "$cache_file"
|
||||
cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true
|
||||
|
||||
# Return sorted file
|
||||
|
||||
Reference in New Issue
Block a user