mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
* Add configuration options for FileMode Add two additional configuration values, and their corresponding default values: * DirFileModeBeforeUmask - Dir FileMode is used on all directories created. DefaultDirFileModeBeforeUmask is 0700. * FileFileModeBeforeUmask - File FileMode is used on all files created, except for the "lock" file (managed by the Flock library). DefaultFileFileModeBeforeUmask is 0600. When using these bits of configuration, keep in mind these FileMode values are set BEFORE any umask rules are applied. For example, if the user's umask is 022, setting DirFileFileModeBeforeUmask to 777 will result in directories with FileMode set to 755 (this umask prevents the write bit from being applied to group and world permissions). * moving defer statements after checking for errors use os.ModePerm const instead of os.FileMode(777) * fix spelling/grammar * skip these tests for Windows as they appear to break - Windows is less POSIX-y than it claims * ignore "lock" file for default case too -- this was incorrectly passing before including this, as my local dev station has umask 022
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// Config contains the bitcask configuration parameters
|
|
type Config struct {
|
|
MaxDatafileSize int `json:"max_datafile_size"`
|
|
MaxKeySize uint32 `json:"max_key_size"`
|
|
MaxValueSize uint64 `json:"max_value_size"`
|
|
Sync bool `json:"sync"`
|
|
AutoRecovery bool `json:"autorecovery"`
|
|
DirFileModeBeforeUmask os.FileMode
|
|
FileFileModeBeforeUmask os.FileMode
|
|
}
|
|
|
|
// Load loads a configuration from the given path
|
|
func Load(path string) (*Config, error) {
|
|
var cfg Config
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// Save saves the configuration to the provided path
|
|
func (c *Config) Save(path string) error {
|
|
|
|
data, err := json.Marshal(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = ioutil.WriteFile(path, data, c.FileFileModeBeforeUmask)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|