1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-24 00:55:08 +00:00

refactor: fix modernize lint issues (#539)

This commit is contained in:
Oleksandr Redko
2026-03-05 14:46:12 +02:00
committed by GitHub
parent fc006e32be
commit 603df79a01
7 changed files with 17 additions and 48 deletions

View File

@@ -644,7 +644,7 @@ func TestCalculateDirSizeFastHighFanoutCompletes(t *testing.T) {
// Reproduce high fan-out nested directory pattern that previously risked semaphore deadlock.
const fanout = 256
for i := 0; i < fanout; i++ {
for i := range fanout {
nested := filepath.Join(root, fmt.Sprintf("dir-%03d", i), "nested")
if err := os.MkdirAll(nested, 0o755); err != nil {
t.Fatalf("create nested dir: %v", err)

View File

@@ -70,7 +70,7 @@ func TestEntryHeap(t *testing.T) {
heap.Push(h, dirEntry{Name: "c", Size: 100})
// All have same size, heap property still holds.
for i := 0; i < 3; i++ {
for range 3 {
popped := heap.Pop(h).(dirEntry)
if popped.Size != 100 {
t.Errorf("Pop() size = %d, want 100", popped.Size)

View File

@@ -77,16 +77,7 @@ func scanPathConcurrent(root string, filesScanned, dirsScanned, bytesScanned *in
largeFileMinSize := int64(largeFileWarmupMinSize)
// Worker pool sized for I/O-bound scanning.
numWorkers := max(runtime.NumCPU()*cpuMultiplier, minWorkers)
if numWorkers > maxWorkers {
numWorkers = maxWorkers
}
if numWorkers > len(children) {
numWorkers = len(children)
}
if numWorkers < 1 {
numWorkers = 1
}
numWorkers := max(min(max(runtime.NumCPU()*cpuMultiplier, minWorkers), maxWorkers, len(children)), 1)
sem := make(chan struct{}, numWorkers)
dirSem := make(chan struct{}, min(runtime.NumCPU()*2, maxDirWorkers))
duSem := make(chan struct{}, min(4, runtime.NumCPU())) // limits concurrent du processes
@@ -95,13 +86,7 @@ func scanPathConcurrent(root string, filesScanned, dirsScanned, bytesScanned *in
// Collect results via channels.
// Cap buffer size to prevent memory spikes with huge directories.
entryBufSize := len(children)
if entryBufSize > 4096 {
entryBufSize = 4096
}
if entryBufSize < 1 {
entryBufSize = 1
}
entryBufSize := max(min(len(children), 4096), 1)
entryChan := make(chan dirEntry, entryBufSize)
largeFileChan := make(chan fileEntry, maxLargeFiles*2)