From 61a3238f195ed47e8b90c62a9927d0601e8e3d92 Mon Sep 17 00:00:00 2001 From: tw93 Date: Wed, 28 Jan 2026 11:43:39 +0800 Subject: [PATCH] fix(scan): prevent hang on cyclic symlinks (#378, #379) --- cmd/analyze/scanner.go | 2 +- lib/core/file_ops.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/analyze/scanner.go b/cmd/analyze/scanner.go index 5a0cde3..539fdb0 100644 --- a/cmd/analyze/scanner.go +++ b/cmd/analyze/scanner.go @@ -584,7 +584,7 @@ func getDirectorySizeFromDuWithExclude(path string, excludePath string) (int64, ctx, cancel := context.WithTimeout(context.Background(), duTimeout) defer cancel() - cmd := exec.CommandContext(ctx, "du", "-sk", target) + cmd := exec.CommandContext(ctx, "du", "-skP", target) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr diff --git a/lib/core/file_ops.sh b/lib/core/file_ops.sh index 33a9126..126fcf0 100644 --- a/lib/core/file_ops.sh +++ b/lib/core/file_ops.sh @@ -418,7 +418,7 @@ get_path_size_kb() { # Use || echo 0 to ensure failure in du (e.g. permission error) doesn't exit script under set -e # Pipefail would normally cause the pipeline to fail if du fails, but || handle catches it. local size - size=$(command du -sk "$path" 2> /dev/null | awk 'NR==1 {print $1; exit}' || true) + size=$(command du -skP "$path" 2> /dev/null | awk 'NR==1 {print $1; exit}' || true) # Ensure size is a valid number (fix for non-numeric du output) if [[ "$size" =~ ^[0-9]+$ ]]; then