mirror of
https://github.com/fumiama/dupimage.git
synced 2026-06-26 23:20:27 +08:00
add option -D
This commit is contained in:
48
main.go
48
main.go
@@ -34,6 +34,7 @@ func main() {
|
|||||||
a := flag.Bool("a", false, "action sort")
|
a := flag.Bool("a", false, "action sort")
|
||||||
h := flag.Bool("h", false, "display help")
|
h := flag.Bool("h", false, "display help")
|
||||||
s := flag.Uint("s", 0, "folder sequence number start (exclude)")
|
s := flag.Uint("s", 0, "folder sequence number start (exclude)")
|
||||||
|
d := flag.Bool("D", false, "enable debug-level log output")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *h {
|
if *h {
|
||||||
fmt.Println("Usage:", os.Args[0], "[-adht] ext1 ext2...")
|
fmt.Println("Usage:", os.Args[0], "[-adht] ext1 ext2...")
|
||||||
@@ -45,6 +46,7 @@ func main() {
|
|||||||
if throttle > 64 {
|
if throttle > 64 {
|
||||||
panic("invalid throttle")
|
panic("invalid throttle")
|
||||||
}
|
}
|
||||||
|
isdebu := *d
|
||||||
exts := flag.Args()
|
exts := flag.Args()
|
||||||
for i, e := range exts {
|
for i, e := range exts {
|
||||||
exts[i] = strings.ToLower(e)
|
exts[i] = strings.ToLower(e)
|
||||||
@@ -114,12 +116,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Println("read file success, comparing...")
|
fmt.Println("read file success, comparing...")
|
||||||
duplis := make(map[string]uint, len(chklst))
|
duplis := make(map[uint]uint, len(chklst))
|
||||||
sameset := make([][]uint, 0)
|
sameset := make([][]uint, 0)
|
||||||
for i := 0; i < len(chklst); i++ {
|
for i := 0; i < len(chklst); i++ {
|
||||||
fmt.Print("compare: ", i, " / ", len(chklst), "\r")
|
fmt.Print("compare: ", i, " / ", len(chklst), "\r")
|
||||||
_, ok := duplis[chklst[i].name]
|
if isdebu {
|
||||||
|
fmt.Print('\n')
|
||||||
|
}
|
||||||
|
x, ok := duplis[uint(i)]
|
||||||
if ok {
|
if ok {
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println(chklst[i].name, "already has index", x, "skip")
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
isfirst := true
|
isfirst := true
|
||||||
@@ -130,23 +138,35 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if uint(dis) < throttle {
|
if uint(dis) < throttle {
|
||||||
x, ok := duplis[chklst[j].name]
|
x, ok := duplis[uint(j)]
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println("adding image index", j, "into same set", i)
|
||||||
|
}
|
||||||
if ok { // 该图片已被归入其他组
|
if ok { // 该图片已被归入其他组
|
||||||
hasfound := false
|
hasfound := false
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println("this image has been added into set", x)
|
||||||
|
}
|
||||||
LOP:
|
LOP:
|
||||||
for k, set := range sameset {
|
for k, set := range sameset {
|
||||||
for _, item := range set {
|
for _, item := range set {
|
||||||
if x == item { // 是该图片所属的组
|
if x == item { // 是该图片所属的组
|
||||||
if isfirst { // 首次归类, 直接添加新组
|
if isfirst { // 首次归类, 直接添加新组
|
||||||
sameset[k] = append(sameset[k], uint(i))
|
sameset[k] = append(sameset[k], uint(i))
|
||||||
duplis[chklst[i].name] = uint(i)
|
duplis[uint(i)] = uint(i)
|
||||||
isfirst = false
|
isfirst = false
|
||||||
hasfound = true
|
hasfound = true
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println("is first, add directly")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
INNERLOP:
|
INNERLOP:
|
||||||
for l, set := range sameset {
|
for l, set := range sameset {
|
||||||
for _, item := range set {
|
for _, item := range set {
|
||||||
if item == uint(i) { // 找到旧组
|
if item == uint(i) { // 找到旧组
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println("merge old set", set, "into", sameset[k])
|
||||||
|
}
|
||||||
sameset[k] = append(sameset[k], set...) // 合并
|
sameset[k] = append(sameset[k], set...) // 合并
|
||||||
sameset = append(sameset[:l], sameset[l+1:]...) // 删除
|
sameset = append(sameset[:l], sameset[l+1:]...) // 删除
|
||||||
hasfound = true
|
hasfound = true
|
||||||
@@ -160,15 +180,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hasfound {
|
if !hasfound {
|
||||||
fmt.Println("sameset: ", sameset)
|
fmt.Println("sameset:", sameset)
|
||||||
panic("index " + strconv.Itoa(j) + ", file " + chklst[j].name + " has been marked as set " + strconv.FormatUint(uint64(x), 10) + " but cannot be found in sameset")
|
panic("index " + strconv.Itoa(j) + ", file " + chklst[j].name + " has been marked as set " + strconv.FormatUint(uint64(x), 10) + " but cannot be found in sameset")
|
||||||
}
|
}
|
||||||
} else if isfirst { // 自立新组
|
} else if isfirst { // 自立新组
|
||||||
sameset = append(sameset, []uint{uint(i)})
|
sameset = append(sameset, []uint{uint(i)})
|
||||||
duplis[chklst[i].name] = uint(i)
|
duplis[uint(i)] = uint(i)
|
||||||
isfirst = false
|
isfirst = false
|
||||||
|
if isdebu {
|
||||||
|
fmt.Println("new set:", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
duplis[uint(j)] = uint(i)
|
||||||
|
if isdebu {
|
||||||
|
fmt.Print('\n')
|
||||||
}
|
}
|
||||||
duplis[chklst[j].name] = uint(i)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,20 +209,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("sameset: ", sameset)
|
fmt.Println("sameset:", sameset)
|
||||||
panic("cannot find index " + strconv.FormatUint(uint64(i), 10) + " in sameset")
|
panic("cannot find index " + strconv.FormatUint(uint64(i), 10) + " in sameset")
|
||||||
}
|
}
|
||||||
for k, v := range duplis {
|
for k, v := range duplis {
|
||||||
i := setindex(v)
|
i := setindex(v)
|
||||||
dupset[i] = append(dupset[i], k)
|
dupset[i] = append(dupset[i], chklst[k].name)
|
||||||
}
|
}
|
||||||
j := *s
|
j := *s
|
||||||
for _, lst := range dupset {
|
for _, lst := range dupset {
|
||||||
if len(lst) > 0 {
|
if len(lst) > 0 {
|
||||||
j++
|
j++
|
||||||
fmt.Println("[", j, "] duplicate:", lst)
|
newdir := strconv.FormatUint(uint64(j), 10)
|
||||||
|
fmt.Println("["+newdir+"] duplicate:", lst)
|
||||||
if action {
|
if action {
|
||||||
newdir := strconv.FormatUint(uint64(j), 10)
|
|
||||||
err = os.MkdirAll(newdir, 0755)
|
err = os.MkdirAll(newdir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("ERROR:", err)
|
fmt.Println("ERROR:", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user