mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Refactored Save function for config (#179)
* Refactored Save function for config * Refactored Save function for config
This commit is contained in:
parent
b7e2012b80
commit
643e578585
1
AUTHORS
1
AUTHORS
@ -10,6 +10,7 @@ James Mills <prologic@shortcircuit.net.au>
|
|||||||
Jesse Donat <donatj@gmail.com>
|
Jesse Donat <donatj@gmail.com>
|
||||||
Kebert Xela kebertxela
|
Kebert Xela kebertxela
|
||||||
panyun panyun
|
panyun panyun
|
||||||
|
shiniao <zhuzhezhe95@gmail.com>
|
||||||
Whemoon Jang <palindrom615@gmail.com>
|
Whemoon Jang <palindrom615@gmail.com>
|
||||||
Yury Fedorov orlangure
|
Yury Fedorov orlangure
|
||||||
o2gy84 <o2gy84@gmail.com>
|
o2gy84 <o2gy84@gmail.com>
|
||||||
|
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains the bitcask configuration parameters
|
// Config contains the bitcask configuration parameters
|
||||||
@ -33,23 +32,16 @@ func Load(path string) (*Config, error) {
|
|||||||
|
|
||||||
// Save saves the configuration to the provided path
|
// Save saves the configuration to the provided path
|
||||||
func (c *Config) Save(path string) error {
|
func (c *Config) Save(path string) error {
|
||||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := json.Marshal(c)
|
data, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = f.Write(data); err != nil {
|
err = ioutil.WriteFile(path, data, 0600)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Sync(); err != nil {
|
return nil
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return f.Close()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user