Streamline the map a little
Now an extension can be both
This commit is contained in:
27
main.go
27
main.go
@@ -42,8 +42,7 @@ func main() {
|
|||||||
|
|
||||||
go GetSyncFilesRecursively(dir, files, status)
|
go GetSyncFilesRecursively(dir, files, status)
|
||||||
|
|
||||||
typeByExtension := sync.Map{}
|
extensionTypeCount := sync.Map{}
|
||||||
countByExtension := sync.Map{}
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for file := range files {
|
for file := range files {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@@ -58,15 +57,17 @@ func main() {
|
|||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
if scanner.Scan() {
|
if scanner.Scan() {
|
||||||
ext := filepath.Ext(file)
|
ext := filepath.Ext(file)
|
||||||
count, _ := countByExtension.LoadOrStore(ext, 0)
|
key := ext
|
||||||
if IsStringBinary(scanner.Text()) {
|
if IsStringBinary(scanner.Text()) {
|
||||||
log.Printf("Binary file: %s (%s)", file, ext)
|
key += " (binary)"
|
||||||
typeByExtension.Store(ext, "binary")
|
count, _ := extensionTypeCount.LoadOrStore(key, 0)
|
||||||
countByExtension.Store(ext, count.(int)+1)
|
extensionTypeCount.Store(key, count.(int)+1)
|
||||||
|
//log.Printf("Binary file: %s (%s)", file, ext)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Text file: %s (%s)", file, ext)
|
key += " (text)"
|
||||||
typeByExtension.Store(ext, "text")
|
count, _ := extensionTypeCount.LoadOrStore(key, 0)
|
||||||
countByExtension.Store(ext, count.(int)+1)
|
extensionTypeCount.Store(key, count.(int)+1)
|
||||||
|
//log.Printf("Text file: %s (%s)", file, ext)
|
||||||
}
|
}
|
||||||
} else if err := scanner.Err(); err != nil {
|
} else if err := scanner.Err(); err != nil {
|
||||||
log.Printf("Error reading line from file %s: %v", file, err)
|
log.Printf("Error reading line from file %s: %v", file, err)
|
||||||
@@ -77,12 +78,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
countByExtension.Range(func(key, value any) bool {
|
extensionTypeCount.Range(func(key, value any) bool {
|
||||||
typ, ok := typeByExtension.Load(key)
|
log.Printf("Extension: %s, Count: %d", key, value.(int))
|
||||||
if !ok {
|
|
||||||
typ = "unknown"
|
|
||||||
}
|
|
||||||
log.Printf("Extension: %s, Type: %s, Count: %d", key, typ, value.(int))
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user