Skip to content

Commit

Permalink
Close the file after reading in verifydependencies#main
Browse files Browse the repository at this point in the history
  • Loading branch information
yutedz committed Oct 19, 2019
1 parent 0c91af2 commit a7231fc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions cmd/verifydependencies/verifydependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,26 @@ func main() {

for _, dep := range externalDeps.Dependencies {
for _, refPath := range dep.RefPaths {
file, err := os.Open(refPath.Path)
if err != nil {
log.Fatalf("error opening file %v : %v", refPath.Path, err)
}
matcher := regexp.MustCompile(refPath.Match)
depFileScanner := bufio.NewScanner(file)
var found bool
for depFileScanner.Scan() {
line := depFileScanner.Text()
if matcher.MatchString(line) && strings.Contains(line, dep.Version) {
found = true
break
func() {
file, err := os.Open(refPath.Path)
if err != nil {
log.Fatalf("error opening file %v : %v", refPath.Path, err)
}
}
if !found {
pathsToUpdate = append(pathsToUpdate, refPath.Path)
}
defer file.Close()
matcher := regexp.MustCompile(refPath.Match)
depFileScanner := bufio.NewScanner(file)
var found bool
for depFileScanner.Scan() {
line := depFileScanner.Text()
if matcher.MatchString(line) && strings.Contains(line, dep.Version) {
found = true
break
}
}
if !found {
pathsToUpdate = append(pathsToUpdate, refPath.Path)
}
}()
}
if len(pathsToUpdate) > 0 {
log.Fatalf(mismatchErrorMessage, externalDepsFilePath, dep.Name, dep.Version, strings.Join(pathsToUpdate, "\n"), dep.Name, externalDepsFilePath)
Expand Down

0 comments on commit a7231fc

Please sign in to comment.