1
0
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:
shiniao 2020-10-29 19:47:08 +08:00 committed by GitHub
parent b7e2012b80
commit 643e578585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 12 deletions

View File

@ -10,6 +10,7 @@ James Mills <prologic@shortcircuit.net.au>
Jesse Donat <donatj@gmail.com>
Kebert Xela kebertxela
panyun panyun
shiniao <zhuzhezhe95@gmail.com>
Whemoon Jang <palindrom615@gmail.com>
Yury Fedorov orlangure
o2gy84 <o2gy84@gmail.com>

View File

@ -3,7 +3,6 @@ package config
import (
"encoding/json"
"io/ioutil"
"os"
)
// Config contains the bitcask configuration parameters
@ -33,23 +32,16 @@ func Load(path string) (*Config, error) {
// Save saves the configuration to the provided path
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)
if err != nil {
return err
}
if _, err = f.Write(data); err != nil {
err = ioutil.WriteFile(path, data, 0600)
if err != nil {
return err
}
if err = f.Sync(); err != nil {
return err
}
return f.Close()
return nil
}