File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed
Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -860,7 +860,11 @@ clean_application_support_logs() {
860860 local app_name_lower
861861 app_name_lower=$( echo " $app_name " | LC_ALL=C tr ' [:upper:]' ' [:lower:]' )
862862 local is_protected=false
863- if should_protect_data " $app_name " ; then
863+ if is_path_whitelisted " $app_dir " 2> /dev/null; then
864+ is_protected=true
865+ elif should_protect_path " $app_dir " 2> /dev/null; then
866+ is_protected=true
867+ elif should_protect_data " $app_name " ; then
864868 is_protected=true
865869 elif should_protect_data " $app_name_lower " ; then
866870 is_protected=true
@@ -874,6 +878,9 @@ clean_application_support_logs() {
874878 local -a start_candidates=(" $app_dir /log" " $app_dir /logs" " $app_dir /activitylog" " $app_dir /Cache/Cache_Data" " $app_dir /Crashpad/completed" )
875879 for candidate in " ${start_candidates[@]} " ; do
876880 if [[ -d " $candidate " ]]; then
881+ if should_protect_path " $candidate " 2> /dev/null || is_path_whitelisted " $candidate " 2> /dev/null; then
882+ continue
883+ fi
877884 # Quick count check - skip if too many items to avoid hanging
878885 local quick_count
879886 quick_count=$( app_support_entry_count_capped " $candidate " 1 101)
@@ -901,6 +908,9 @@ clean_application_support_logs() {
901908 local candidate_item_count=0
902909 while IFS= read -r -d ' ' item; do
903910 [[ -e " $item " ]] || continue
911+ if should_protect_path " $item " 2> /dev/null || is_path_whitelisted " $item " 2> /dev/null; then
912+ continue
913+ fi
904914 item_found=true
905915 candidate_item_count=$(( candidate_item_count + 1 ))
906916 if [[ ! -L " $item " && (-f " $item " || -d " $item " ) ]]; then
Original file line number Diff line number Diff line change @@ -290,6 +290,8 @@ readonly DATA_PROTECTED_BUNDLES=(
290290 " clash.*"
291291 " Clash.*"
292292 " clash_*"
293+ " *clash-verge*"
294+ " *Clash-Verge*"
293295 " clashverge*"
294296 " ClashVerge*"
295297 " com.nssurge.surge-mac"
@@ -694,7 +696,7 @@ should_protect_data() {
694696 com.nssurge.* | com.v2ray.* | com.clash.* | ClashX* | Surge* | Shadowrocket* | Quantumult* )
695697 return 0
696698 ;;
697- clash-* | Clash-* | * -clash | * -Clash | clash.* | Clash.* | clash_* | clashverge* | ClashVerge* )
699+ clash-* | Clash-* | * -clash | * -Clash | clash.* | Clash.* | clash_* | * clash-verge * | * Clash-Verge * | clashverge* | ClashVerge* )
698700 return 0
699701 ;;
700702 com.docker.* | com.getpostman.* | com.insomnia.* )
Original file line number Diff line number Diff line change 255255 [[ " $output " != * " REMOVE:" * ]]
256256}
257257
258+ @test " clean_application_support_logs skips whitelisted application support directories" {
259+ local support_home=" $HOME /support-appsupport-whitelist"
260+ run env HOME=" $support_home " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
261+ set -euo pipefail
262+ mkdir -p "$HOME"
263+ source "$PROJECT_ROOT/lib/core/common.sh"
264+ source "$PROJECT_ROOT/lib/clean/user.sh"
265+ start_section_spinner() { :; }
266+ stop_section_spinner() { :; }
267+ note_activity() { :; }
268+ safe_remove() { echo "REMOVE:$1"; }
269+ update_progress_if_needed() { return 1; }
270+ should_protect_data() { return 1; }
271+ is_critical_system_component() { return 1; }
272+ WHITELIST_PATTERNS=("$HOME/Library/Application Support/io.github.clash-verge-rev.clash-verge-rev")
273+ files_cleaned=0
274+ total_size_cleaned=0
275+ total_items=0
276+
277+ mkdir -p "$HOME/Library/Application Support/io.github.clash-verge-rev.clash-verge-rev/logs"
278+ touch "$HOME/Library/Application Support/io.github.clash-verge-rev.clash-verge-rev/logs/runtime.log"
279+
280+ clean_application_support_logs
281+ test -f "$HOME/Library/Application Support/io.github.clash-verge-rev.clash-verge-rev/logs/runtime.log"
282+ rm -rf "$HOME/Library/Application Support"
283+ EOF
284+
285+ [ " $status " -eq 0 ]
286+ [[ " $output " != * " REMOVE:" * ]]
287+ }
288+
258289@test " app_support_entry_count_capped stops at cap without failing under pipefail" {
259290 local support_home=" $HOME /support-appsupport-cap"
260291 run env HOME=" $support_home " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
Original file line number Diff line number Diff line change 142142 result=$( HOME=" $HOME " bash --noprofile --norc -c " source '$PROJECT_ROOT /lib/core/common.sh'; should_protect_data 'com.clash.app' && echo 'protected' || echo 'not-protected'" )
143143 [ " $result " = " protected" ]
144144
145+ result=$( HOME=" $HOME " bash --noprofile --norc -c " source '$PROJECT_ROOT /lib/core/common.sh'; should_protect_data 'io.github.clash-verge-rev.clash-verge-rev' && echo 'protected' || echo 'not-protected'" )
146+ [ " $result " = " protected" ]
147+
145148 result=$( HOME=" $HOME " bash --noprofile --norc -c " source '$PROJECT_ROOT /lib/core/common.sh'; should_protect_data 'com.example.RegularApp' && echo 'protected' || echo 'not-protected'" )
146149 [ " $result " = " not-protected" ]
147150}
You can’t perform that action at this time.
0 commit comments