--- a/goduf.go Sun Sep 30 13:07:06 2018 +0200
+++ b/goduf.go Sat Oct 13 21:42:11 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2017 Mikael Berthe <mikael@lilotux.net>
+ * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net>
*
* 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
@@ -33,7 +33,6 @@
"flag"
"fmt"
"io"
- "log"
"os"
"path/filepath"
"sort"
@@ -73,37 +72,9 @@
var data dataT
-type myLogT struct {
- verbosity int
-}
-
// Implement my own logger
var myLog myLogT
-func (l *myLogT) Printf(level int, format string, args ...interface{}) {
- if level > l.verbosity {
- return
- }
- if level >= 0 {
- log.Printf(format, args...)
- return
- }
- // Error message without timestamp
- fmt.Fprintf(os.Stderr, format, args...)
-}
-
-func (l *myLogT) Println(level int, args ...interface{}) {
- if level > l.verbosity {
- return
- }
- if level >= 0 {
- log.Println(args...)
- return
- }
- // Error message without timestamp
- fmt.Fprintln(os.Stderr, args...)
-}
-
// visit is called for every file and directory.
// We check the file object is correct (regular, readable...) and add
// it to the data.sizeGroups hash.
@@ -487,7 +458,7 @@
// Assertion on constant values
if minSizePartialChecksum <= 2*medsumBytes {
- log.Fatal("Internal error: assert minSizePartialChecksum > 2*medsumBytes")
+ myLog.Fatal("Internal error: assert minSizePartialChecksum > 2*medsumBytes")
}
// Command line parameters parsingg
@@ -520,7 +491,7 @@
// Change log format for benchmarking
if *timings {
- log.SetFlags(log.LstdFlags | log.Lmicroseconds)
+ myLog.SetBenchFlags()
}
data.sizeGroups = make(map[int64]*FileObjList)
@@ -621,26 +592,3 @@
myLog.Println(summaryLevel, "Redundant data size:",
formatSize(dupeSize, false))
}
-
-// Implement a sort interface for the list of duplicate groups
-type byGroupFileSize foListList
-
-func (a byGroupFileSize) Len() int { return len(a) }
-func (a byGroupFileSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-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()
-}
-
-// Implement a sort interface for a slice of files
-type byFilePathName FileObjList
-
-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].FilePath < a[j].FilePath
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/logging.go Sat Oct 13 21:42:11 2018 +0200
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+ "os"
+)
+
+type myLogT struct {
+ verbosity int
+}
+
+func (l *myLogT) Printf(level int, format string, args ...interface{}) {
+ if level > l.verbosity {
+ return
+ }
+ if level >= 0 {
+ log.Printf(format, args...)
+ return
+ }
+ // Error message without timestamp
+ fmt.Fprintf(os.Stderr, format, args...)
+}
+
+func (l *myLogT) Println(level int, args ...interface{}) {
+ if level > l.verbosity {
+ return
+ }
+ if level >= 0 {
+ log.Println(args...)
+ return
+ }
+ // Error message without timestamp
+ fmt.Fprintln(os.Stderr, args...)
+}
+
+func (l *myLogT) Fatal(args ...interface{}) {
+ log.Fatal(args...)
+}
+
+func (l *myLogT) SetBenchFlags() {
+ log.SetFlags(log.LstdFlags | log.Lmicroseconds)
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sort.go Sat Oct 13 21:42:11 2018 +0200
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+package main
+
+// Implement a sort interface for the list of duplicate groups
+type byGroupFileSize foListList
+
+func (a byGroupFileSize) Len() int { return len(a) }
+func (a byGroupFileSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+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()
+}
+
+// Implement a sort interface for a slice of files
+type byFilePathName FileObjList
+
+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].FilePath < a[j].FilePath
+}