mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-05-18 14:11:55 +02:00
Reenable commented logic
This commit is contained in:
parent
f8564f20ac
commit
587f904ebc
150
main.go
150
main.go
@ -1,12 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"slices"
|
"slices"
|
||||||
@ -45,11 +51,11 @@ func main() {
|
|||||||
var countFiles int64 = 0
|
var countFiles int64 = 0
|
||||||
filesMap := newFilesMap()
|
filesMap := newFilesMap()
|
||||||
if *fromFile != "" {
|
if *fromFile != "" {
|
||||||
// byteValue, _ := ioutil.ReadFile(*fromFile)
|
byteValue, _ := ioutil.ReadFile(*fromFile)
|
||||||
// err := json.Unmarshal(byteValue, &filesMap.FilesByHash)
|
err := json.Unmarshal(byteValue, &filesMap.FilesByHash)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// panic(err)
|
panic(err)
|
||||||
// }
|
}
|
||||||
} else {
|
} else {
|
||||||
filesMap.incomingBar = filesMap.progress.AddSpinner(0,
|
filesMap.incomingBar = filesMap.progress.AddSpinner(0,
|
||||||
mpb.PrependDecorators(
|
mpb.PrependDecorators(
|
||||||
@ -103,87 +109,87 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *toFile != "" && *fromFile == "" {
|
if *toFile != "" && *fromFile == "" {
|
||||||
// json, _ := json.MarshalIndent(filesMap.FilesByHash, "", " ")
|
json, _ := json.MarshalIndent(filesMap.FilesByHash, "", " ")
|
||||||
// ioutil.WriteFile(*toFile, json, 0644)
|
ioutil.WriteFile(*toFile, json, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *deleteDupesIn != "" {
|
if *deleteDupesIn != "" {
|
||||||
/* deleteIn := filepath.Clean(*deleteDupesIn)
|
deleteIn := filepath.Clean(*deleteDupesIn)
|
||||||
for hash := range filesMap.FilesByHash {
|
for hash := range filesMap.FilesByHash {
|
||||||
duplicateFiles := filesMap.FilesByHash[hash]
|
duplicateFiles := filesMap.FilesByHash[hash]
|
||||||
if len(duplicateFiles) <= 1 {
|
if len(duplicateFiles) <= 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDupesInFolder := false
|
hasDupesInFolder := false
|
||||||
hasDupesOutsideFolder := false
|
hasDupesOutsideFolder := false
|
||||||
for _, file := range duplicateFiles {
|
for _, file := range duplicateFiles {
|
||||||
fileIsInFolder := strings.HasPrefix(filepath.Clean(file), deleteIn)
|
fileIsInFolder := strings.HasPrefix(filepath.Clean(file), deleteIn)
|
||||||
hasDupesOutsideFolder = hasDupesOutsideFolder || !fileIsInFolder
|
hasDupesOutsideFolder = hasDupesOutsideFolder || !fileIsInFolder
|
||||||
hasDupesInFolder = hasDupesInFolder || fileIsInFolder
|
hasDupesInFolder = hasDupesInFolder || fileIsInFolder
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasDupesInFolder || !hasDupesOutsideFolder {
|
if !hasDupesInFolder || !hasDupesOutsideFolder {
|
||||||
if !hasDupesOutsideFolder {
|
if !hasDupesOutsideFolder {
|
||||||
fmt.Println("Not deleting one of the following files, since all would be deleted")
|
fmt.Println("Not deleting one of the following files, since all would be deleted")
|
||||||
}
|
}
|
||||||
if !hasDupesInFolder {
|
if !hasDupesInFolder {
|
||||||
fmt.Println("Not deleting one of the following files, since none are in the selected directory")
|
fmt.Println("Not deleting one of the following files, since none are in the selected directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range duplicateFiles {
|
for _, file := range duplicateFiles {
|
||||||
fmt.Println("-", file)
|
fmt.Println("-", file)
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range duplicateFiles {
|
for _, file := range duplicateFiles {
|
||||||
if strings.HasPrefix(filepath.Clean(file), deleteIn) {
|
if strings.HasPrefix(filepath.Clean(file), deleteIn) {
|
||||||
fmt.Println("Would delete ", file)
|
fmt.Println("Would delete ", file)
|
||||||
if *force {
|
if *force {
|
||||||
remove(file)
|
remove(file)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if *promptForDelete {
|
} else if *promptForDelete {
|
||||||
/* reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
for hash := range filesMap.FilesByHash {
|
for hash := range filesMap.FilesByHash {
|
||||||
duplicateFiles := filesMap.FilesByHash[hash]
|
duplicateFiles := filesMap.FilesByHash[hash]
|
||||||
if len(duplicateFiles) <= 1 {
|
if len(duplicateFiles) <= 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("\033[H\033[2J")
|
fmt.Print("\033[H\033[2J")
|
||||||
for i, file := range duplicateFiles {
|
for i, file := range duplicateFiles {
|
||||||
fmt.Println(i+1, file)
|
fmt.Println(i+1, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Which file to keep? ")
|
fmt.Printf("Which file to keep? ")
|
||||||
input, err := reader.ReadString('\n')
|
input, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Invalid input")
|
fmt.Println("Invalid input")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
input = strings.TrimRight(input, "\n\r")
|
input = strings.TrimRight(input, "\n\r")
|
||||||
intInput, err := strconv.Atoi(input)
|
intInput, err := strconv.Atoi(input)
|
||||||
if err != nil || intInput > len(duplicateFiles) || intInput < 1 {
|
if err != nil || intInput > len(duplicateFiles) || intInput < 1 {
|
||||||
fmt.Println("Invalid input")
|
fmt.Println("Invalid input")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, file := range duplicateFiles {
|
for i, file := range duplicateFiles {
|
||||||
if i+1 == intInput {
|
if i+1 == intInput {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if *force {
|
if *force {
|
||||||
remove(file)
|
remove(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
} else {
|
} else {
|
||||||
countInstances := 0
|
countInstances := 0
|
||||||
countDupeSets := 0
|
countDupeSets := 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user