# HG changeset patch # User Mikael Berthe # Date 1487524904 -3600 # Node ID dee0e0c1ad10cf5de198863dd3273124cd9b9d28 # Parent f7ce9d750e8323b92b6aae5df625e291aa90fa39 Improve file sorting diff -r f7ce9d750e83 -r dee0e0c1ad10 goduf.go --- a/goduf.go Sun Jun 29 18:30:02 2014 +0200 +++ b/goduf.go Sun Feb 19 18:21:44 2017 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Mikael Berthe + * Copyright (C) 2014-2017 Mikael Berthe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -556,7 +556,12 @@ if len(result) > 0 && !summary { myLog.Println(1, "* Dupes:") } - // Sort by increasing size (of the files, not groups) + + // Sort files by path inside each group + for _, l := range result { + sort.Sort(byFilePathName(l)) + } + // Sort groups by increasing size (of the duplicated files) sort.Sort(byGroupFileSize(result)) var dupeSize uint64 @@ -570,7 +575,6 @@ fmt.Printf("\nGroup #%d (%d files * %v):\n", i+1, len(l), formatSize(size, true)) } - sort.Sort(byFilePathName(l)) for _, f := range l { if !summary { fmt.Println(f.FilePath) @@ -603,6 +607,9 @@ func (a byGroupFileSize) Less(i, j int) bool { // Since this is supposed to be used for duplicate lists, // we use the size of the first file of the group. + if a[i][0].Size() == a[j][0].Size() { + return a[i][0].FilePath < a[j][0].FilePath + } return a[i][0].Size() < a[j][0].Size() } @@ -612,5 +619,5 @@ func (a byFilePathName) Len() int { return len(a) } func (a byFilePathName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a byFilePathName) Less(i, j int) bool { - return a[i].Name() < a[j].Name() + return a[i].FilePath < a[j].FilePath }