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