forked from mirror/viper
Fixed missing f.Close() in writeConfig()
Defering can cause trouble because we're writing to the file outside the function where the defering is registered, calling f.Sync() ensures that bytes are flushed to disk even is Close() is called too soon.
This commit is contained in:
parent
e325492b82
commit
e02bc9eca5
8
viper.go
8
viper.go
|
@ -1378,7 +1378,13 @@ func (v *Viper) writeConfig(filename string, force bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return v.marshalWriter(f, configType)
|
||||
defer f.Close()
|
||||
|
||||
if err := v.marshalWriter(f, configType); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return f.Sync()
|
||||
}
|
||||
|
||||
// Unmarshal a Reader into a map.
|
||||
|
|
Loading…
Reference in New Issue