Switch to doublestar from custom walker
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.qodo
|
2
go.mod
2
go.mod
@@ -1,3 +1,5 @@
|
|||||||
module binarysusser
|
module binarysusser
|
||||||
|
|
||||||
go 1.24.1
|
go 1.24.1
|
||||||
|
|
||||||
|
require github.com/bmatcuk/doublestar/v4 v4.8.1
|
||||||
|
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38=
|
||||||
|
github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
|
91
main.go
91
main.go
@@ -9,8 +9,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"github.com/bmatcuk/doublestar/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Error *log.Logger
|
var Error *log.Logger
|
||||||
@@ -50,15 +50,14 @@ func main() {
|
|||||||
log.Printf("Scanning directory: %s", dir)
|
log.Printf("Scanning directory: %s", dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make(chan string, 10000)
|
files, err := doublestar.Glob(os.DirFS(dir), "**/*")
|
||||||
status := make(chan error)
|
if err != nil {
|
||||||
go GetSyncFilesRecursively(dir, files, status)
|
log.Fatalf("Error globbing directory: %v", err)
|
||||||
//files <- "SmarterConstruction.pdb"
|
}
|
||||||
|
|
||||||
extensionTypeCount := sync.Map{}
|
extensionTypeCount := sync.Map{}
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for file := range files {
|
for _, file := range files {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(file string) {
|
go func(file string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@@ -320,82 +319,6 @@ func IsStringBinary(s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSyncFilesRecursively(input string, output chan string, status chan error) {
|
|
||||||
defer close(output)
|
|
||||||
defer close(status)
|
|
||||||
|
|
||||||
var filesProcessed int32
|
|
||||||
var foldersProcessed int32
|
|
||||||
var activeWorkers int32
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
defer close(done)
|
|
||||||
|
|
||||||
directories := make(chan string, 100000)
|
|
||||||
workerPool := make(chan struct{}, 4000)
|
|
||||||
directories <- input
|
|
||||||
|
|
||||||
allDone := make(chan struct{})
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
if atomic.LoadInt32(&activeWorkers) == 0 && len(directories) == 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
if atomic.LoadInt32(&activeWorkers) == 0 && len(directories) == 0 {
|
|
||||||
close(allDone)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case directory, ok := <-directories:
|
|
||||||
if !ok {
|
|
||||||
wg.Wait()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic.AddInt32(&activeWorkers, 1)
|
|
||||||
|
|
||||||
go func(dir string) {
|
|
||||||
workerPool <- struct{}{}
|
|
||||||
|
|
||||||
atomic.AddInt32(&foldersProcessed, 1)
|
|
||||||
processDirectory(dir, directories, output, &filesProcessed)
|
|
||||||
|
|
||||||
<-workerPool
|
|
||||||
atomic.AddInt32(&activeWorkers, -1)
|
|
||||||
}(directory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
<-allDone
|
|
||||||
}
|
|
||||||
|
|
||||||
func processDirectory(directory string, directories chan<- string, output chan<- string, filesProcessed *int32) {
|
|
||||||
files, err := os.ReadDir(directory)
|
|
||||||
if err != nil {
|
|
||||||
//log.Printf("Error reading directory %s: %+v", directory, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if file.IsDir() {
|
|
||||||
directories <- filepath.Join(directory, file.Name())
|
|
||||||
} else {
|
|
||||||
output <- filepath.Join(directory, file.Name())
|
|
||||||
atomic.AddInt32(filesProcessed, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NormalizePath(input string) string {
|
func NormalizePath(input string) string {
|
||||||
input = filepath.Clean(input)
|
input = filepath.Clean(input)
|
||||||
input = filepath.ToSlash(input)
|
input = filepath.ToSlash(input)
|
||||||
|
Reference in New Issue
Block a user