Skip to content

Commit 0f834b6

Browse files
authored
Merge pull request kubernetes#84108 from yutedz/verify-dep-close
Close the file after reading in verifydependencies#main
2 parents 9790262 + a7231fc commit 0f834b6

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

cmd/verifydependencies/verifydependencies.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,26 @@ func main() {
7272

7373
for _, dep := range externalDeps.Dependencies {
7474
for _, refPath := range dep.RefPaths {
75-
file, err := os.Open(refPath.Path)
76-
if err != nil {
77-
log.Fatalf("error opening file %v : %v", refPath.Path, err)
78-
}
79-
matcher := regexp.MustCompile(refPath.Match)
80-
depFileScanner := bufio.NewScanner(file)
81-
var found bool
82-
for depFileScanner.Scan() {
83-
line := depFileScanner.Text()
84-
if matcher.MatchString(line) && strings.Contains(line, dep.Version) {
85-
found = true
86-
break
75+
func() {
76+
file, err := os.Open(refPath.Path)
77+
if err != nil {
78+
log.Fatalf("error opening file %v : %v", refPath.Path, err)
8779
}
88-
}
89-
if !found {
90-
pathsToUpdate = append(pathsToUpdate, refPath.Path)
91-
}
80+
defer file.Close()
81+
matcher := regexp.MustCompile(refPath.Match)
82+
depFileScanner := bufio.NewScanner(file)
83+
var found bool
84+
for depFileScanner.Scan() {
85+
line := depFileScanner.Text()
86+
if matcher.MatchString(line) && strings.Contains(line, dep.Version) {
87+
found = true
88+
break
89+
}
90+
}
91+
if !found {
92+
pathsToUpdate = append(pathsToUpdate, refPath.Path)
93+
}
94+
}()
9295
}
9396
if len(pathsToUpdate) > 0 {
9497
log.Fatalf(mismatchErrorMessage, externalDepsFilePath, dep.Name, dep.Version, strings.Join(pathsToUpdate, "\n"), dep.Name, externalDepsFilePath)

0 commit comments

Comments
 (0)