1 /* |
1 /* |
2 * Copyright (C) 2014 Mikael Berthe <mikael@lilotux.net> |
2 * Copyright (C) 2014-2017 Mikael Berthe <mikael@lilotux.net> |
3 * |
3 * |
4 * This program is free software; you can redistribute it and/or modify |
4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by |
5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; either version 2 of the License, or (at |
6 * the Free Software Foundation; either version 2 of the License, or (at |
7 * your option) any later version. |
7 * your option) any later version. |
554 |
554 |
555 // Done! Dump dupes |
555 // Done! Dump dupes |
556 if len(result) > 0 && !summary { |
556 if len(result) > 0 && !summary { |
557 myLog.Println(1, "* Dupes:") |
557 myLog.Println(1, "* Dupes:") |
558 } |
558 } |
559 // Sort by increasing size (of the files, not groups) |
559 |
|
560 // Sort files by path inside each group |
|
561 for _, l := range result { |
|
562 sort.Sort(byFilePathName(l)) |
|
563 } |
|
564 // Sort groups by increasing size (of the duplicated files) |
560 sort.Sort(byGroupFileSize(result)) |
565 sort.Sort(byGroupFileSize(result)) |
561 |
566 |
562 var dupeSize uint64 |
567 var dupeSize uint64 |
563 data.cmpt = 0 |
568 data.cmpt = 0 |
564 for i, l := range result { |
569 for i, l := range result { |
568 dupeSize += size * uint64(len(l)-1) |
573 dupeSize += size * uint64(len(l)-1) |
569 if !summary { |
574 if !summary { |
570 fmt.Printf("\nGroup #%d (%d files * %v):\n", i+1, |
575 fmt.Printf("\nGroup #%d (%d files * %v):\n", i+1, |
571 len(l), formatSize(size, true)) |
576 len(l), formatSize(size, true)) |
572 } |
577 } |
573 sort.Sort(byFilePathName(l)) |
|
574 for _, f := range l { |
578 for _, f := range l { |
575 if !summary { |
579 if !summary { |
576 fmt.Println(f.FilePath) |
580 fmt.Println(f.FilePath) |
577 } |
581 } |
578 data.cmpt++ |
582 data.cmpt++ |
601 func (a byGroupFileSize) Len() int { return len(a) } |
605 func (a byGroupFileSize) Len() int { return len(a) } |
602 func (a byGroupFileSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
606 func (a byGroupFileSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
603 func (a byGroupFileSize) Less(i, j int) bool { |
607 func (a byGroupFileSize) Less(i, j int) bool { |
604 // Since this is supposed to be used for duplicate lists, |
608 // Since this is supposed to be used for duplicate lists, |
605 // we use the size of the first file of the group. |
609 // we use the size of the first file of the group. |
|
610 if a[i][0].Size() == a[j][0].Size() { |
|
611 return a[i][0].FilePath < a[j][0].FilePath |
|
612 } |
606 return a[i][0].Size() < a[j][0].Size() |
613 return a[i][0].Size() < a[j][0].Size() |
607 } |
614 } |
608 |
615 |
609 // Implement a sort interface for a slice of files |
616 // Implement a sort interface for a slice of files |
610 type byFilePathName FileObjList |
617 type byFilePathName FileObjList |
611 |
618 |
612 func (a byFilePathName) Len() int { return len(a) } |
619 func (a byFilePathName) Len() int { return len(a) } |
613 func (a byFilePathName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
620 func (a byFilePathName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
614 func (a byFilePathName) Less(i, j int) bool { |
621 func (a byFilePathName) Less(i, j int) bool { |
615 return a[i].Name() < a[j].Name() |
622 return a[i].FilePath < a[j].FilePath |
616 } |
623 } |