cmd/hakurei/parse: close config fd
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m5s
Test / Sandbox (race detector) (push) Successful in 3m54s
Test / Hpkg (push) Successful in 3m57s
Test / Hakurei (race detector) (push) Successful in 4m43s
Test / Flake checks (push) Successful in 1m20s
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m5s
Test / Sandbox (race detector) (push) Successful in 3m54s
Test / Hpkg (push) Successful in 3m57s
Test / Hakurei (race detector) (push) Successful in 4m43s
Test / Flake checks (push) Successful in 1m20s
This is cleaner than relying on the finalizer. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
fbd1638e7f
commit
ea978101b1
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func tryPath(msg message.Msg, name string) (config *hst.Config) {
|
||||
var r io.Reader
|
||||
var r io.ReadCloser
|
||||
config = new(hst.Config)
|
||||
|
||||
if name != "-" {
|
||||
@ -25,23 +25,20 @@ func tryPath(msg message.Msg, name string) (config *hst.Config) {
|
||||
msg.Verbose("load configuration from file")
|
||||
|
||||
if f, err := os.Open(name); err != nil {
|
||||
log.Fatalf("cannot access configuration file %q: %s", name, err)
|
||||
log.Fatal(err.Error())
|
||||
return
|
||||
} else {
|
||||
// finalizer closes f
|
||||
r = f
|
||||
}
|
||||
} else {
|
||||
defer func() {
|
||||
if err := r.(io.ReadCloser).Close(); err != nil {
|
||||
log.Printf("cannot close config fd: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
r = os.Stdin
|
||||
}
|
||||
|
||||
decodeJSON(log.Fatal, "load configuration", r, &config)
|
||||
if err := r.Close(); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user