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

Side by Side Diff: common/dirwalk/walk_basic.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: Fixes. Created 4 years, 2 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 // 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698