Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |