1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 19:00:54 +00:00

fix session file write bug

This commit is contained in:
slene 2013-05-14 07:33:00 +08:00
parent 98b245c746
commit 6d3486e2a6

View File

@ -32,7 +32,6 @@ func (fs *FileSessionStore) Set(key, value interface{}) error {
func (fs *FileSessionStore) Get(key interface{}) interface{} { func (fs *FileSessionStore) Get(key interface{}) interface{} {
fs.lock.RLock() fs.lock.RLock()
defer fs.lock.RUnlock() defer fs.lock.RUnlock()
fs.updatecontent()
if v, ok := fs.values[key]; ok { if v, ok := fs.values[key]; ok {
return v return v
} else { } else {
@ -58,13 +57,13 @@ func (fs *FileSessionStore) SessionRelease() {
} }
func (fs *FileSessionStore) updatecontent() { func (fs *FileSessionStore) updatecontent() {
if len(fs.values) > 0 { b, err := encodeGob(fs.values)
b, err := encodeGob(fs.values) if err != nil {
if err != nil { return
return
}
fs.f.Write(b)
} }
fs.f.Truncate(0)
fs.f.Seek(0, 0)
fs.f.Write(b)
} }
type FileProvider struct { type FileProvider struct {
@ -107,7 +106,7 @@ func (fp *FileProvider) SessionRead(sid string) (SessionStore, error) {
} }
} }
f.Close() f.Close()
f, err = os.Create(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid)) f, err = os.OpenFile(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid), os.O_WRONLY|os.O_CREATE, 0777)
ss := &FileSessionStore{f: f, sid: sid, values: kv} ss := &FileSessionStore{f: f, sid: sid, values: kv}
return ss, nil return ss, nil
} }