|
1 /* |
|
2 * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net> |
|
3 * |
|
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 |
|
6 * the Free Software Foundation; either version 2 of the License, or (at |
|
7 * your option) any later version. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, but |
|
10 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
17 * USA |
|
18 */ |
|
19 |
|
20 package main |
|
21 |
|
22 import ( |
|
23 "encoding/json" |
|
24 "fmt" |
|
25 ) |
|
26 |
|
27 func displayResults(results Results, jsonOutput bool, summaryOnly bool) { |
|
28 if jsonOutput { |
|
29 displayResultsJSON(results) |
|
30 return |
|
31 } |
|
32 |
|
33 if !summaryOnly { |
|
34 for i, g := range results.Groups { |
|
35 fmt.Printf("\nGroup #%d (%d files * %v):\n", i+1, |
|
36 len(g.Paths), formatSize(g.Size, true)) |
|
37 for _, f := range g.Paths { |
|
38 fmt.Println(f) |
|
39 } |
|
40 } |
|
41 } |
|
42 |
|
43 // We're done if we do not display statistics |
|
44 if myLog.verbosity < 1 && !summaryOnly { |
|
45 return |
|
46 } |
|
47 |
|
48 // Add a trailing newline |
|
49 if len(results.Groups) > 0 && myLog.verbosity > 0 { |
|
50 fmt.Println() |
|
51 } |
|
52 myLog.Println(0, "Final count:", results.Duplicates, |
|
53 "duplicate files in", len(results.Groups), "sets") |
|
54 myLog.Println(0, "Redundant data size:", |
|
55 formatSize(results.RedundantDataSize, false)) |
|
56 } |
|
57 |
|
58 func displayResultsJSON(results Results) { |
|
59 b, err := json.Marshal(results) |
|
60 if err != nil { |
|
61 panic(err) |
|
62 } |
|
63 fmt.Println(string(b)) |
|
64 } |