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

Fix the symbolic link jump issue

This commit is contained in:
Tw93
2025-11-20 20:14:08 +08:00
parent 4c0a4baf77
commit 0f0ca3912c
3 changed files with 36 additions and 1 deletions

Binary file not shown.

View File

@@ -75,6 +75,27 @@ func scanPathConcurrent(root string, filesScanned, dirsScanned, bytesScanned *in
for _, child := range children { for _, child := range children {
fullPath := filepath.Join(root, child.Name()) fullPath := filepath.Join(root, child.Name())
// Skip symlinks to avoid following them into unexpected locations
// Use Type() instead of IsDir() to check without following symlinks
if child.Type()&fs.ModeSymlink != 0 {
// For symlinks, get their target info but mark them specially
info, err := child.Info()
if err != nil {
continue
}
size := getActualFileSize(fullPath, info)
atomic.AddInt64(&total, size)
entryChan <- dirEntry{
Name: child.Name() + " →", // Add arrow to indicate symlink
Path: fullPath,
Size: size,
IsDir: false, // Don't allow navigation into symlinks
LastAccess: getLastAccessTimeFromInfo(info),
}
continue
}
if child.IsDir() { if child.IsDir() {
// In root directory, skip system directories completely // In root directory, skip system directories completely
if isRootDir && skipSystemDirs[child.Name()] { if isRootDir && skipSystemDirs[child.Name()] {
@@ -383,6 +404,20 @@ func calculateDirSizeConcurrent(root string, largeFileChan chan<- fileEntry, fil
for _, child := range children { for _, child := range children {
fullPath := filepath.Join(root, child.Name()) fullPath := filepath.Join(root, child.Name())
// Skip symlinks to avoid following them into unexpected locations
if child.Type()&fs.ModeSymlink != 0 {
// For symlinks, just count their size without following
info, err := child.Info()
if err != nil {
continue
}
size := getActualFileSize(fullPath, info)
total += size
atomic.AddInt64(filesScanned, 1)
atomic.AddInt64(bytesScanned, size)
continue
}
if child.IsDir() { if child.IsDir() {
// Check if this is a folded directory // Check if this is a folded directory
if shouldFoldDirWithPath(child.Name(), fullPath) { if shouldFoldDirWithPath(child.Name(), fullPath) {

2
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh" source "$SCRIPT_DIR/lib/common.sh"
# Version info # Version info
VERSION="1.9.17" VERSION="1.9.18"
MOLE_TAGLINE="can dig deep to clean your Mac." MOLE_TAGLINE="can dig deep to clean your Mac."
# Get latest version from remote repository # Get latest version from remote repository