@@ -6,12 +6,13 @@ import (
6
6
"flag"
7
7
"fmt"
8
8
"log"
9
-
10
- "github.com/kivisade/tabfmt"
11
- "github.com/dustin/go-humanize"
12
9
"time"
13
10
"regexp"
14
11
"strconv"
12
+ "runtime"
13
+
14
+ "github.com/kivisade/tabfmt"
15
+ "github.com/dustin/go-humanize"
15
16
)
16
17
17
18
func p2 (n uint64 ) (p uint ) {
@@ -107,6 +108,9 @@ func (s *StatCounter) Walk(path string, f os.FileInfo, err error) (abort error)
107
108
return
108
109
}
109
110
if f .IsDir () {
111
+ if runtime .GOOS [:] == "windows" && f .Mode () & os .ModeSymlink != 0 { // NB: runtime.GOOS[:] is to mute the annoying "condition is always true" warning
112
+ return filepath .SkipDir
113
+ }
110
114
return
111
115
}
112
116
s .addFile (uint64 (f .Size ()))
@@ -176,19 +180,28 @@ func (s *StatCounter) GetTotalCount() uint64 {
176
180
return s .totalCount
177
181
}
178
182
183
+ func (s * StatCounter ) GetTotalOverhead () uint64 {
184
+ return s .totalOverhead
185
+ }
186
+
179
187
func main () {
180
188
var (
181
- stats * StatCounter
182
- ready chan error = make (chan error )
183
- running bool = true
184
- root string
185
- block string
186
- blockSz uint64
187
- out string
188
- start time.Time
189
- runtime time.Duration
190
- totalCount uint64
191
- fps float64
189
+ stats * StatCounter
190
+ ready chan error = make (chan error )
191
+ running bool = true
192
+ err error
193
+ root string
194
+ block string
195
+ blockSz uint64
196
+ out string
197
+ start time.Time
198
+ runningTime time.Duration
199
+ totalCount uint64
200
+ fps float64
201
+ ohdActual uint64
202
+ ohdEstimate uint64
203
+ ohdPrc float64
204
+ ohdSgn string = "better"
192
205
)
193
206
194
207
flag .StringVar (& out , "out" , "formatted" , "Output format ('formatted' for pretty-printed table or 'tab' for Excel-friendly tabbed format)" )
@@ -227,24 +240,33 @@ func main() {
227
240
}
228
241
}()
229
242
230
- if err := <- ready ; err != nil {
231
- running = false
243
+ if err , running = <- ready , false ; err != nil {
232
244
log .Printf ("Error while recursively walking %s: %s" , root , err )
233
245
}
234
246
235
- runtime = time .Since (start )
247
+ runningTime = time .Since (start )
236
248
if totalCount = stats .GetTotalCount (); totalCount > 0 {
237
- fps = float64 (totalCount ) / runtime .Seconds ()
249
+ fps = float64 (totalCount ) / runningTime .Seconds ()
238
250
}
239
251
252
+ fmt .Println ()
253
+
240
254
switch out {
241
255
case "formatted" :
242
256
stats .Print ()
243
257
default :
244
258
stats .PrintSimple ()
245
259
}
246
260
247
- fmt .Printf ("\n Scanned %d files in %s (avg. %.2f files per second).\n " , totalCount , runtime , fps )
248
- fmt .Printf ("Rough estimate of overhead per %d files using allocation units of %d bytes is %s.\n " ,
249
- totalCount , blockSz , humanize .Bytes (totalCount * blockSz / 2 ))
261
+ ohdActual , ohdEstimate = stats .GetTotalOverhead (), totalCount * blockSz / 2
262
+ ohdPrc = 1 - float64 (ohdActual ) / float64 (ohdEstimate )
263
+ if ohdPrc < 0 {
264
+ ohdPrc *= - 1
265
+ ohdSgn = "worse"
266
+ }
267
+
268
+ fmt .Printf ("\n Scanned %d files in %s (avg. %.2f files per second).\n \n " , totalCount , runningTime , fps )
269
+ fmt .Printf ("Rough estimate of overhead per %d files using allocation units of %d bytes is %s. " +
270
+ "Actual overhead of %s is %.2f%% %s.\n " ,
271
+ totalCount , blockSz , humanize .Bytes (ohdEstimate ), humanize .Bytes (ohdActual ), 100 * ohdPrc , ohdSgn )
250
272
}
0 commit comments