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 // Trivial implementation of a directory tree walker using the WalkObserver |
| 14 // interface. |
| 15 func WalkBasic(root string, smallfile_limit int64, obs WalkObserver) { |
| 16 filepath.Walk(root, func(path string, info os.FileInfo, err error) error
{ |
| 17 if err != nil { |
| 18 obs.Error(path, err) |
| 19 return nil |
| 20 } |
| 21 |
| 22 if info.IsDir() { |
| 23 return nil |
| 24 } |
| 25 |
| 26 if info.Size() < smallfile_limit { |
| 27 data, err := ioutil.ReadFile(path) |
| 28 if err != nil { |
| 29 obs.Error(path, err) |
| 30 return nil |
| 31 } |
| 32 if int64(len(data)) != info.Size() { |
| 33 panic("file size was wrong!") |
| 34 } |
| 35 obs.SmallFile(path, data) |
| 36 } else { |
| 37 obs.LargeFile(path) |
| 38 } |
| 39 return nil |
| 40 }) |
| 41 obs.Finished() |
| 42 } |
OLD | NEW |