OLD | NEW |
1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package venv | 5 package venv |
6 | 6 |
7 import ( | 7 import ( |
8 "io" | 8 "io" |
9 "os" | 9 "os" |
10 "strings" | 10 "strings" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 return nil | 70 return nil |
71 }) | 71 }) |
72 } | 72 } |
73 | 73 |
74 func iterDir(c context.Context, dirPath string, cb func([]os.FileInfo) error) er
ror { | 74 func iterDir(c context.Context, dirPath string, cb func([]os.FileInfo) error) er
ror { |
75 // Get a listing of all VirtualEnv within the base directory. | 75 // Get a listing of all VirtualEnv within the base directory. |
76 dir, err := os.Open(dirPath) | 76 dir, err := os.Open(dirPath) |
77 if err != nil { | 77 if err != nil { |
78 » » return errors.Annotate(err).Reason("failed to open base director
y: %(dir)s"). | 78 » » return errors.Annotate(err, "failed to open base directory: %s",
dirPath).Err() |
79 » » » D("dir", dirPath). | |
80 » » » Err() | |
81 } | 79 } |
82 defer dir.Close() | 80 defer dir.Close() |
83 | 81 |
84 for done := false; !done; { | 82 for done := false; !done; { |
85 // Check if we've been cancelled. | 83 // Check if we've been cancelled. |
86 select { | 84 select { |
87 case <-c.Done(): | 85 case <-c.Done(): |
88 return c.Err() | 86 return c.Err() |
89 default: | 87 default: |
90 } | 88 } |
91 | 89 |
92 // Read the next batch of directories. | 90 // Read the next batch of directories. |
93 fileInfos, err := dir.Readdir(forEachReadDirSize) | 91 fileInfos, err := dir.Readdir(forEachReadDirSize) |
94 switch err { | 92 switch err { |
95 case nil: | 93 case nil: |
96 | 94 |
97 case io.EOF: | 95 case io.EOF: |
98 done = true | 96 done = true |
99 | 97 |
100 default: | 98 default: |
101 » » » return errors.Annotate(err).Reason("could not read direc
tory contents: %(dir)s"). | 99 » » » return errors.Annotate(err, "could not read directory co
ntents: %s", dirPath).Err() |
102 » » » » D("dir", dirPath). | |
103 » » » » Err() | |
104 } | 100 } |
105 | 101 |
106 if err := cb(fileInfos); err != nil { | 102 if err := cb(fileInfos); err != nil { |
107 return err | 103 return err |
108 } | 104 } |
109 } | 105 } |
110 | 106 |
111 return nil | 107 return nil |
112 } | 108 } |
OLD | NEW |