Skip to content

Commit

Permalink
fix: close file before sorting the content of input file
Browse files Browse the repository at this point in the history
  • Loading branch information
wonsikin committed Apr 1, 2019
1 parent 105e5d5 commit 35a23e3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ func Parser(input, output string, unsorted bool) (err error) {
if err != nil {
return err
}
defer file.Close()

header, body, err := ReadContent(file)
if err != nil {
fmt.Printf("fail when reading input file: %v\n", err)
return err
}

fileName := file.Name()
// Close file to avoid crash when sort file content
file.Close()

// sort content by key
if !unsorted {
err = sortInputFile(file.Name(), header, body)
err = sortInputFile(fileName, header, body)
if err != nil {
fmt.Printf("fail when sorting input file: %v\n", err)
return err
Expand Down

0 comments on commit 35a23e3

Please sign in to comment.