-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split functions in
filewalker.go
This refactoring will increase readability and maintainability of the code. There are no functional changes.
- Loading branch information
Showing
3 changed files
with
58 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package filewalker | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
workerPool "github.com/nlnwa/warchaeology/internal/workerpool" | ||
) | ||
|
||
func closePool(walker *fileWalker, pool *workerPool.WorkerPool, resultChan chan Result, allResults *sync.WaitGroup, startTime time.Time, stats Stats) { | ||
pool.CloseWait() | ||
resultChan <- nil | ||
allResults.Wait() | ||
timeSpent := time.Since(startTime) | ||
if walker.isLog(summaryLogType) { | ||
walker.logSummary(fmt.Sprintf("Total time: %v, %s", timeSpent, stats)) | ||
} else if walker.isLog(progressLogType) { | ||
fmt.Printf(" \r") | ||
} | ||
} | ||
|
||
func printResultsAndProgress(walker *fileWalker, resultChan chan Result, allResults *sync.WaitGroup, stats Stats) { | ||
count := 0 | ||
for { | ||
result := <-resultChan | ||
if result == nil { | ||
allResults.Done() | ||
break | ||
} | ||
count++ | ||
if result.ErrorCount() > 0 && walker.isLog(errorLogType) { | ||
walker.logError(result, count) | ||
} else if walker.isLog(infoLogType) { | ||
walker.logInfo(result, count) | ||
} | ||
|
||
stats.Merge(result.GetStats()) | ||
if result.Fatal() != nil { | ||
fmt.Printf("ERROR: %s\n", result.Fatal()) | ||
} | ||
|
||
if walker.isLog(progressLogType) { | ||
fmt.Printf(" %s %s\r", string(anim[animPos]), stats.String()) | ||
animPos++ | ||
if animPos >= len(anim) { | ||
animPos = 0 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters