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

Side by Side Diff: common/dirwalk/tests/tools/walkdir/fileprocessor_verify.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: Major rewrite of the code. Created 4 years, 1 month 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 main
6
7 import (
8 "io"
9 "log"
10 "os"
11 "strings"
12 )
13
14 // VerifyFileProcessor implements FileProcessor. It verifies that things are cal led in the right order.
15 type VerifyFileProcessor struct {
16 BaseFileProcessor
17 rootDir string
18 finishedDirs []string
19 }
20
21 func (p *VerifyFileProcessor) check(path string) {
22 for _, d := range p.finishedDirs {
23 if strings.HasPrefix(path, d) {
24 log.Fatalf("Directory called before content\n Dir: %s \nContent: %s\n", path, d)
25 }
26 }
27 }
28
29 func (p *VerifyFileProcessor) checkFile(path string) {
30 stat, err := os.Stat(path)
31 if err != nil {
32 log.Fatalf("Error while stating small file\n%s", path)
33 }
34 if stat.IsDir() {
35 log.Fatalf("File function called with directory!\n%s", path)
36 }
37 p.check(path)
38 }
39
40 func (p *VerifyFileProcessor) Dir(path string) {
41 stat, err := os.Stat(path)
42 if err != nil {
43 log.Fatalf("Error while stating directory\n%s", path)
44 }
45 if !stat.IsDir() {
46 log.Fatalf("Dir() called with non-directory!\n%s", path)
47 }
48 p.check(path)
49 p.finishedDirs = append(p.finishedDirs, path)
50 p.BaseFileProcessor.Dir(path)
51 }
52
53 func (p *VerifyFileProcessor) SmallFile(path string, r io.ReadCloser) {
54 p.checkFile(path)
55 p.BaseFileProcessor.SmallFile(path, r)
56 }
57
58 func (p *VerifyFileProcessor) LargeFile(path string, r io.ReadCloser) {
59 p.checkFile(path)
60 p.BaseFileProcessor.LargeFile(path, r)
61 }
62
63 func (p *VerifyFileProcessor) Finished() {
64 if strings.Compare(p.finishedDirs[len(p.finishedDirs)-1], p.rootDir) != 0 {
65 log.Fatalf("Last directory should be the root\n%s\n%s", p.finish edDirs[len(p.finishedDirs)-1], p.rootDir)
66 }
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698