Skip to content

Commit

Permalink
Merge pull request robyoung#17 from go-graphite/cmd/convert-close-files
Browse files Browse the repository at this point in the history
cmd/convert.go: should close files properly after opening it
  • Loading branch information
azhiltsov authored Apr 20, 2020
2 parents 12c0eec + f8da8af commit f2ba40d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func convert(path string, progressc chan string, convertingCount *int64, convert
if err != nil {
return fmt.Errorf("convert: failed to open %s: %s", path, err)
}
defer func() {
if err := db.File().Close(); err != nil {
fmt.Printf("convert: failed to close converted file %s: %s", path, err)
}
}()

if db.IsCompressed() {
if debugf {
Expand Down Expand Up @@ -268,6 +273,8 @@ func convert(path string, progressc chan string, convertingCount *int64, convert
if err != nil {
return fmt.Errorf("convert: failed to open %s: %s", tmpPath, err)
}
defer cfile.Close()

cstat, err := cfile.Stat()
if err != nil {
return fmt.Errorf("convert: failed to stat %s: %s", tmpPath, err)
Expand All @@ -285,10 +292,6 @@ func convert(path string, progressc chan string, convertingCount *int64, convert
return fmt.Errorf("convert: failed to copy compressed data for %s: %s", path, err)
}

if err := db.File().Close(); err != nil {
return fmt.Errorf("convert: failed to close converted file %s: %s", path, err)
}

return nil
}

Expand Down

0 comments on commit f2ba40d

Please sign in to comment.