mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
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
d493c32b69
commit
e8b4ff02fe
1 changed files with 7 additions and 1 deletions
8
viper.go
8
viper.go
|
@ -1266,7 +1266,13 @@ func (v *Viper) writeConfig(filename string, force bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// Unmarshal a Reader into a map.
|
||||||
|
|
Loading…
Add table
Reference in a new issue