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

Side by Side Diff: common/dirwalk/walkbasic.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: Small updates. Created 4 years, 3 months 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 dirwalk
6
7 import (
8 "io/ioutil"
9 "os"
10 "path/filepath"
11 )
12
13 /**
M-A Ruel 2016/09/15 14:31:03 same
mithro 2016/09/20 12:41:45 I assume you mean regarding the comment style? Do
14 Trivial implementation of a directory tree walker using the WalkObserver
15 interface.
16 */
17 func WalkBasic(root string, smallfile_limit int64, obs WalkObserver) {
18 filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
19 if err != nil {
20 obs.Error(path, err)
21 return nil
22 }
23
24 if info.IsDir() {
25 return nil
26 }
27
28 if info.Size() < smallfile_limit {
29 data, err := ioutil.ReadFile(path)
30 if err != nil {
31 obs.Error(path, err)
32 return nil
33 }
34 if int64(len(data)) != info.Size() {
35 panic("file size was wrong!")
36 }
37 obs.SmallFile(path, data)
38 } else {
39 obs.LargeFile(path)
40 }
41 return nil
42 })
43 obs.Finished()
M-A Ruel 2016/09/15 14:31:03 I don't see the point, the caller knows when it's
mithro 2016/09/20 12:41:45 It is normal that the observer needs to be notifie
M-A Ruel 2016/09/20 16:37:27 The caller knows the walk terminated because WalkB
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698