X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=store%2Fstore.go;h=8bdf317c4fd79ca38d4113439152ad3b80bacb6e;hb=ba050281925d304417cc0d4a80340b9dab9b6da8;hp=2595f88213f479a80873d63fa3c5957f74826d33;hpb=c89b19c863fc41c0312358a866aebd425f498c76;p=epoint diff --git a/store/store.go b/store/store.go index 2595f88..8bdf317 100644 --- a/store/store.go +++ b/store/store.go @@ -8,12 +8,11 @@ package store // TODO: this is a toy implementation import ( + "io/ioutil" "os" "path/filepath" - "io/ioutil" ) - type Conn struct { path string } @@ -41,8 +40,7 @@ func (c *Conn) Ensure(name string) (err error) { func (c *Conn) Set(name, k string, v []byte) (err error) { fn := filepath.Join(c.path, name, k) - // os.O_SYNC - f, err := os.Create(fn+".tmp") + f, err := os.OpenFile(fn+".tmp", os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_SYNC, 0666) if err != nil { return } @@ -55,6 +53,17 @@ func (c *Conn) Set(name, k string, v []byte) (err error) { return } +func (c *Conn) Append(name, k string, v []byte) (err error) { + fn := filepath.Join(c.path, name, k) + f, err := os.OpenFile(fn, os.O_CREATE|os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0666) + if err != nil { + return + } + defer f.Close() + _, err = f.Write(v) + return +} + func (c *Conn) Close() (err error) { return }