1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 17:24:45 +00:00

feat: add support for custom protected paths and update whitelist UI with config path and examples

This commit is contained in:
Tw93
2025-12-21 20:59:45 +08:00
parent f23ab89db0
commit b3b2a83613
2 changed files with 32 additions and 4 deletions

View File

@@ -486,6 +486,28 @@ should_protect_path() {
local path="$1"
[[ -z "$path" ]] && return 1
# 0. Check custom protected paths first
local custom_config="$HOME/.config/mole/protected_paths"
if [[ -f "$custom_config" ]]; then
while IFS= read -r protected_path; do
# Trim whitespace
protected_path="${protected_path#"${protected_path%%[![:space:]]*}"}"
protected_path="${protected_path%"${protected_path##*[![:space:]]}"}"
# Skip empty lines and comments
[[ -z "$protected_path" || "$protected_path" =~ ^# ]] && continue
# Expand ~ to $HOME in protected path
protected_path="${protected_path/#\~/$HOME}"
# Check if path starts with protected path (prefix match)
# This protects both the directory and everything under it
if [[ "$path" == "$protected_path" || "$path" == "$protected_path"/* ]]; then
return 0
fi
done < "$custom_config"
fi
local path_lower
path_lower=$(echo "$path" | tr '[:upper:]' '[:lower:]')