Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: common/dirwalk/tests/tools/walkdir/fileprocessor.go

Issue 2054763004: luci-go/common/dirwalk: Code for walking a directory tree efficiently Base URL: https://github.com/luci/luci-go@master
Patch Set: Major rewrite of the code. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "io"
9 "log"
10 "sync/atomic"
11 )
12
13 // FileProcessor is a basic interface for processing files provided by the
14 // directory walking functions.
15 type FileProcessor interface {
16 // Dir is called when a directory has been finished.
17 Dir(path string)
18
19 // SmallFile is called for processing a file which has been classed as " small".
20 SmallFile(path string, r io.ReadCloser)
21
22 // LargeFile is called for processing a file which has been classed as " large".
23 LargeFile(path string, r io.ReadCloser)
24
25 // Error is called when an error occurs on a path.
26 Error(path string, err error)
27
28 // Finished is called when the directory walk is finished.
29 Finished()
30 }
31
32 // BaseFileProcessor implements FileProcessor and counts the number of files of
33 // each type.
34 type BaseFileProcessor struct {
35 smallFiles uint64
36 largeFiles uint64
37 dirs uint64
38 }
39
40 func (p *BaseFileProcessor) Dir(path string) {
41 atomic.AddUint64(&p.dirs, 1)
42 }
43
44 func (p *BaseFileProcessor) SmallFile(path string, r io.ReadCloser) {
45 atomic.AddUint64(&p.smallFiles, 1)
46 if r != nil {
47 r.Close()
48 }
49 }
50
51 func (p *BaseFileProcessor) LargeFile(path string, r io.ReadCloser) {
52 atomic.AddUint64(&p.largeFiles, 1)
53 if r != nil {
54 r.Close()
55 }
56 }
57
58 func (p *BaseFileProcessor) Error(path string, err error) {
59 log.Fatalf("%s:%s", path, err)
60 }
61
62 func (p *BaseFileProcessor) Finished() {
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698