2013-11-05 09:59:00 +00:00
|
|
|
package metastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// store data on disk, enough for most cases
|
|
|
|
|
|
|
|
type MetaStoreFileBacking struct {
|
|
|
|
}
|
|
|
|
|
2013-11-10 09:31:50 +00:00
|
|
|
func NewMetaStoreFileBacking() *MetaStoreFileBacking {
|
|
|
|
mms := &MetaStoreFileBacking{}
|
2013-11-05 09:59:00 +00:00
|
|
|
return mms
|
|
|
|
}
|
|
|
|
|
2013-11-10 09:31:50 +00:00
|
|
|
func (mms *MetaStoreFileBacking) Set(path, val string) error {
|
|
|
|
return ioutil.WriteFile(path, []byte(val), 0644)
|
2013-11-05 09:59:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 09:31:50 +00:00
|
|
|
func (mms *MetaStoreFileBacking) Get(path string) (string, error) {
|
|
|
|
val, e := ioutil.ReadFile(path)
|
|
|
|
return string(val), e
|
2013-11-05 09:59:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 09:31:50 +00:00
|
|
|
func (mms *MetaStoreFileBacking) Has(path string) (ok bool) {
|
|
|
|
seqFile, se := os.OpenFile(path, os.O_RDONLY, 0644)
|
2013-11-05 09:59:00 +00:00
|
|
|
if se != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
defer seqFile.Close()
|
|
|
|
return true
|
|
|
|
}
|