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

Side by Side Diff: common/dirwalk/tests/tools/gendir/main.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: Rebase onto master. 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 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 // Generate directory tree following a given structure.
8
9 import (
10 "encoding/json"
11 "flag"
12 "fmt"
13 "io/ioutil"
14 "log"
15 "math/rand"
16 "os"
17 )
18
19 type TestSettings struct {
20 Name string
21 Comment string
22 Seed int64
23 Tree TreeSettings
24 }
25
26 var config = flag.String("config", "", "JSON config file for generating test fil e.")
27 var outdir = flag.String("outdir", "", "Where to write the output.")
28 var seed = flag.Int64("seed", 4, "Seed for random.")
29
30 func main() {
31 flag.Parse()
32
33 var settings TestSettings
34 settings.Seed = *seed
35
36 configdata, err := ioutil.ReadFile(*config)
37 if err != nil {
38 log.Fatal(err)
39 }
40
41 if err := json.Unmarshal(configdata, &settings); err != nil {
42 log.Fatal(err)
43 }
44
45 fmt.Printf("%s: %s\n", settings.Name, settings.Comment)
46 fmt.Println("===============================================")
47 fmt.Println()
48
49 if len(*outdir) == 0 {
50 log.Fatal("No output directory supplied.")
51 }
52
53 if _, err := os.Stat(*outdir); !os.IsNotExist(err) {
54 log.Fatal("directory exists!")
55 }
56
57 if *seed != 4 && settings.Seed != *seed {
58 log.Fatal("Seed supplied by test config.")
59 }
60
61 r := rand.New(rand.NewSource(settings.Seed))
62
63 // Create the root directory
64 if err := os.MkdirAll(*outdir, 0755); err != nil {
65 log.Fatal(err)
66 }
67
68 GenerateTree(r, *outdir, &settings.Tree)
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698