storage
This commit is contained in:
parent
103ec07f92
commit
9b9920b5ed
35
main.go
35
main.go
@ -4,10 +4,10 @@ import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -16,10 +16,10 @@ import (
|
||||
)
|
||||
|
||||
type FileQuality struct {
|
||||
Path string
|
||||
Bitrate int
|
||||
Bitdepth int
|
||||
Size int64
|
||||
Path string
|
||||
Bitrate int
|
||||
Bitdepth int
|
||||
Size int64
|
||||
}
|
||||
|
||||
var (
|
||||
@ -149,6 +149,19 @@ func findDuplicateFiles(rootDir string) (map[string][]FileQuality, error) {
|
||||
return fileGroups, nil
|
||||
}
|
||||
|
||||
func bytesToHumanReadable(bytes int64) string {
|
||||
const unit = 1024
|
||||
if bytes < unit {
|
||||
return fmt.Sprintf("%d B", bytes)
|
||||
}
|
||||
div, exp := int64(unit), 0
|
||||
for n := bytes / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
func processFileGroup(baseFile string, files []FileQuality) {
|
||||
writeLog(fmt.Sprintf("Processing group for: %s", baseFile))
|
||||
|
||||
@ -212,11 +225,11 @@ func processFileGroup(baseFile string, files []FileQuality) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
writeLog(fmt.Sprintf(" * %s: %s (Recovering %d bytes)", action, file.Path, file.Size))
|
||||
writeLog(fmt.Sprintf(" * %s: %s (Recovering %s)", action, file.Path, bytesToHumanReadable(file.Size)))
|
||||
}
|
||||
}
|
||||
|
||||
writeLog(fmt.Sprintf(" Total recoverable space: %d bytes", totalSize-bestFile.Size))
|
||||
writeLog(fmt.Sprintf(" Total recoverable space: %s", bytesToHumanReadable(totalSize-bestFile.Size)))
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -271,11 +284,19 @@ func main() {
|
||||
writeLog("")
|
||||
}
|
||||
|
||||
var totalRecoverableSpace int64
|
||||
|
||||
for baseFile, group := range fileGroups {
|
||||
processFileGroup(baseFile, group)
|
||||
for _, file := range group {
|
||||
if file.Path != baseFile {
|
||||
totalRecoverableSpace += file.Size
|
||||
}
|
||||
}
|
||||
writeLog("")
|
||||
}
|
||||
|
||||
writeLog(fmt.Sprintf("Total recoverable space: %s", bytesToHumanReadable(totalRecoverableSpace)))
|
||||
writeLog(fmt.Sprintf("Cleanup completed at %s", getCurrentTime()))
|
||||
writeLog("===============================")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user