mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 14:26:46 +00:00
chore: auto format code
This commit is contained in:
@@ -306,7 +306,7 @@ func calculateDirSizeFast(root string, filesScanned, dirsScanned, bytesScanned *
|
||||
subDir := filepath.Join(dirPath, entry.Name())
|
||||
go func(p string) {
|
||||
defer wg.Done()
|
||||
sem <- struct{}{} // Acquire token
|
||||
sem <- struct{}{} // Acquire token
|
||||
defer func() { <-sem }() // Release token
|
||||
walk(p)
|
||||
}(subDir)
|
||||
|
||||
@@ -163,22 +163,22 @@ func (c *Collector) Collect() (MetricsSnapshot, error) {
|
||||
hostInfo, _ := host.Info()
|
||||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
errMu sync.Mutex
|
||||
mergeErr error
|
||||
wg sync.WaitGroup
|
||||
errMu sync.Mutex
|
||||
mergeErr error
|
||||
|
||||
cpuStats CPUStatus
|
||||
memStats MemoryStatus
|
||||
diskStats []DiskStatus
|
||||
diskIO DiskIOStatus
|
||||
netStats []NetworkStatus
|
||||
proxyStats ProxyStatus
|
||||
cpuStats CPUStatus
|
||||
memStats MemoryStatus
|
||||
diskStats []DiskStatus
|
||||
diskIO DiskIOStatus
|
||||
netStats []NetworkStatus
|
||||
proxyStats ProxyStatus
|
||||
batteryStats []BatteryStatus
|
||||
thermalStats ThermalStatus
|
||||
sensorStats []SensorReading
|
||||
gpuStats []GPUStatus
|
||||
btStats []BluetoothDevice
|
||||
topProcs []ProcessInfo
|
||||
sensorStats []SensorReading
|
||||
gpuStats []GPUStatus
|
||||
btStats []BluetoothDevice
|
||||
topProcs []ProcessInfo
|
||||
)
|
||||
|
||||
// Helper to launch concurrent collection
|
||||
|
||||
@@ -164,8 +164,8 @@ scan_installed_apps() {
|
||||
|
||||
(
|
||||
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
|
||||
-name "*.plist" -type f 2> /dev/null |
|
||||
xargs -I {} basename {} .plist > "$scan_tmp_dir/agents.txt" 2> /dev/null || true
|
||||
-name "*.plist" -type f 2> /dev/null |
|
||||
xargs -I {} basename {} .plist > "$scan_tmp_dir/agents.txt" 2> /dev/null || true
|
||||
) &
|
||||
pids+=($!)
|
||||
|
||||
@@ -212,7 +212,6 @@ is_bundle_orphaned() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# Extra check for specific system bundles not covered by patterns
|
||||
case "$bundle_id" in
|
||||
loginwindow | dock | systempreferences | finder | safari)
|
||||
|
||||
@@ -38,7 +38,7 @@ clean_orphaned_casks() {
|
||||
rm -f "$cask_cache" 2> /dev/null || true
|
||||
true > "$cask_cache"
|
||||
|
||||
while IFS= read -r cask; do
|
||||
while IFS= read -r cask; do
|
||||
# Get app path from cask info with timeout protection (expensive call, hence caching)
|
||||
local cask_info
|
||||
cask_info=$(run_with_timeout 10 brew info --cask "$cask" 2> /dev/null || true)
|
||||
@@ -62,12 +62,11 @@ clean_orphaned_casks() {
|
||||
# Check if app exists into common locations
|
||||
# We must check both /Applications and ~/Applications
|
||||
if [[ ! -e "/Applications/$app_name" ]] && [[ ! -e "$HOME/Applications/$app_name" ]]; then
|
||||
orphaned_casks+=("$cask")
|
||||
orphaned_casks+=("$cask")
|
||||
fi
|
||||
done < <(brew list --cask 2> /dev/null || true)
|
||||
fi
|
||||
|
||||
|
||||
# Remove orphaned casks if found and sudo session is still valid
|
||||
if [[ ${#orphaned_casks[@]} -gt 0 ]]; then
|
||||
# Check if sudo session is still valid (without prompting)
|
||||
|
||||
@@ -52,8 +52,6 @@ clean_deep_system() {
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# Clean macOS Install Data (system upgrade leftovers)
|
||||
# Only remove if older than 30 days to ensure system stability
|
||||
if [[ -d "/macOS Install Data" ]]; then
|
||||
|
||||
@@ -734,23 +734,23 @@ find_app_receipt_files() {
|
||||
# Whitelisted prefixes
|
||||
case "$clean_path" in
|
||||
/Applications/*) is_safe=true ;;
|
||||
/Users/*) is_safe=true ;;
|
||||
/usr/local/*) is_safe=true ;;
|
||||
/opt/*) is_safe=true ;;
|
||||
/Users/*) is_safe=true ;;
|
||||
/usr/local/*) is_safe=true ;;
|
||||
/opt/*) is_safe=true ;;
|
||||
/Library/*)
|
||||
# Filter sub-paths in /Library to avoid system damage
|
||||
# Allow safely: Application Support, Caches, Logs, Preferences
|
||||
case "$clean_path" in
|
||||
/Library/Application\ Support/*) is_safe=true ;;
|
||||
/Library/Caches/*) is_safe=true ;;
|
||||
/Library/Logs/*) is_safe=true ;;
|
||||
/Library/Preferences/*) is_safe=true ;;
|
||||
/Library/Caches/*) is_safe=true ;;
|
||||
/Library/Logs/*) is_safe=true ;;
|
||||
/Library/Preferences/*) is_safe=true ;;
|
||||
/Library/PrivilegedHelperTools/*) is_safe=true ;;
|
||||
/Library/LaunchAgents/*) is_safe=true ;;
|
||||
/Library/LaunchDaemons/*) is_safe=true ;;
|
||||
/Library/Internet\ Plug-Ins/*) is_safe=true ;;
|
||||
/Library/Audio/Plug-Ins/*) is_safe=true ;;
|
||||
/Library/Extensions/*) is_safe=false ;; # Default unsafe
|
||||
/Library/LaunchAgents/*) is_safe=true ;;
|
||||
/Library/LaunchDaemons/*) is_safe=true ;;
|
||||
/Library/Internet\ Plug-Ins/*) is_safe=true ;;
|
||||
/Library/Audio/Plug-Ins/*) is_safe=true ;;
|
||||
/Library/Extensions/*) is_safe=false ;; # Default unsafe
|
||||
*) is_safe=false ;;
|
||||
esac
|
||||
;;
|
||||
@@ -758,7 +758,7 @@ find_app_receipt_files() {
|
||||
|
||||
# Hard blocks
|
||||
case "$clean_path" in
|
||||
/System/*|/usr/bin/*|/usr/lib/*|/bin/*|/sbin/*) is_safe=false ;;
|
||||
/System/* | /usr/bin/* | /usr/lib/* | /bin/* | /sbin/*) is_safe=false ;;
|
||||
esac
|
||||
|
||||
if [[ "$is_safe" == "true" && -e "$clean_path" ]]; then
|
||||
@@ -774,7 +774,7 @@ find_app_receipt_files() {
|
||||
# Extra check: path must be deep enough?
|
||||
# If path is just "/Applications", skip.
|
||||
if [[ "$clean_path" == "/Applications" || "$clean_path" == "/Library" || "$clean_path" == "/usr/local" ]]; then
|
||||
continue
|
||||
continue
|
||||
fi
|
||||
|
||||
receipt_files+=("$clean_path")
|
||||
|
||||
@@ -127,7 +127,7 @@ log_system_info() {
|
||||
echo "Shell: ${SHELL:-unknown} (${TERM:-unknown})"
|
||||
|
||||
# Check sudo status non-interactively
|
||||
if sudo -n true 2>/dev/null; then
|
||||
if sudo -n true 2> /dev/null; then
|
||||
echo "Sudo Access: Active"
|
||||
else
|
||||
echo "Sudo Access: Required"
|
||||
|
||||
@@ -254,12 +254,12 @@ perform_updates() {
|
||||
|
||||
if [[ -x "$mole_bin" ]]; then
|
||||
if "$mole_bin" update 2>&1 | grep -qE "(Updated|latest version)"; then
|
||||
echo -e "${GREEN}✓${NC} Mole updated"
|
||||
reset_mole_cache
|
||||
((updated_count++))
|
||||
else
|
||||
echo -e "${RED}✗${NC} Mole update failed"
|
||||
fi
|
||||
echo -e "${GREEN}✓${NC} Mole updated"
|
||||
reset_mole_cache
|
||||
((updated_count++))
|
||||
else
|
||||
echo -e "${RED}✗${NC} Mole update failed"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}✗${NC} Mole executable not found"
|
||||
fi
|
||||
|
||||
@@ -16,8 +16,6 @@ opt_system_maintenance() {
|
||||
echo -e "${RED}${ICON_ERROR}${NC} Failed to clear DNS cache"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
echo -e "${BLUE}${ICON_ARROW}${NC} Checking Spotlight index..."
|
||||
local md_status
|
||||
md_status=$(mdutil -s / 2> /dev/null || echo "")
|
||||
@@ -31,7 +29,6 @@ opt_system_maintenance() {
|
||||
sudo pkill -f blued 2> /dev/null || true
|
||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Bluetooth controller refreshed"
|
||||
|
||||
|
||||
}
|
||||
|
||||
# Cache refresh: update Finder/Safari caches
|
||||
@@ -112,7 +109,6 @@ opt_radio_refresh() {
|
||||
echo -e "${BLUE}${ICON_ARROW}${NC} Refreshing Wi-Fi service..."
|
||||
# Only restart Wi-Fi service, do NOT delete saved networks
|
||||
|
||||
|
||||
# Safe alternative: just restart the Wi-Fi interface
|
||||
local wifi_interface
|
||||
wifi_interface=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | head -1)
|
||||
|
||||
Reference in New Issue
Block a user