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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: common/dirwalk/walkbasic.go
diff --git a/common/dirwalk/walkbasic.go b/common/dirwalk/walkbasic.go
new file mode 100644
index 0000000000000000000000000000000000000000..056dae89b1990ee6b05fdda9cc5be7db599ca3bb
--- /dev/null
+++ b/common/dirwalk/walkbasic.go
@@ -0,0 +1,44 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package dirwalk
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+/**
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
+Trivial implementation of a directory tree walker using the WalkObserver
+interface.
+*/
+func WalkBasic(root string, smallfile_limit int64, obs WalkObserver) {
+ filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ obs.Error(path, err)
+ return nil
+ }
+
+ if info.IsDir() {
+ return nil
+ }
+
+ if info.Size() < smallfile_limit {
+ data, err := ioutil.ReadFile(path)
+ if err != nil {
+ obs.Error(path, err)
+ return nil
+ }
+ if int64(len(data)) != info.Size() {
+ panic("file size was wrong!")
+ }
+ obs.SmallFile(path, data)
+ } else {
+ obs.LargeFile(path)
+ }
+ return nil
+ })
+ 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
+}

Powered by Google App Engine
This is Rietveld 408576698