1745dd22 by astaxie

Merge pull request #54 from slene/master

fix session file write bug
2 parents 98b245c7 6d3486e2
...@@ -32,7 +32,6 @@ func (fs *FileSessionStore) Set(key, value interface{}) error { ...@@ -32,7 +32,6 @@ func (fs *FileSessionStore) Set(key, value interface{}) error {
32 func (fs *FileSessionStore) Get(key interface{}) interface{} { 32 func (fs *FileSessionStore) Get(key interface{}) interface{} {
33 fs.lock.RLock() 33 fs.lock.RLock()
34 defer fs.lock.RUnlock() 34 defer fs.lock.RUnlock()
35 fs.updatecontent()
36 if v, ok := fs.values[key]; ok { 35 if v, ok := fs.values[key]; ok {
37 return v 36 return v
38 } else { 37 } else {
...@@ -58,13 +57,13 @@ func (fs *FileSessionStore) SessionRelease() { ...@@ -58,13 +57,13 @@ func (fs *FileSessionStore) SessionRelease() {
58 } 57 }
59 58
60 func (fs *FileSessionStore) updatecontent() { 59 func (fs *FileSessionStore) updatecontent() {
61 if len(fs.values) > 0 { 60 b, err := encodeGob(fs.values)
62 b, err := encodeGob(fs.values) 61 if err != nil {
63 if err != nil { 62 return
64 return
65 }
66 fs.f.Write(b)
67 } 63 }
64 fs.f.Truncate(0)
65 fs.f.Seek(0, 0)
66 fs.f.Write(b)
68 } 67 }
69 68
70 type FileProvider struct { 69 type FileProvider struct {
...@@ -107,7 +106,7 @@ func (fp *FileProvider) SessionRead(sid string) (SessionStore, error) { ...@@ -107,7 +106,7 @@ func (fp *FileProvider) SessionRead(sid string) (SessionStore, error) {
107 } 106 }
108 } 107 }
109 f.Close() 108 f.Close()
110 f, err = os.Create(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid)) 109 f, err = os.OpenFile(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid), os.O_WRONLY|os.O_CREATE, 0777)
111 ss := &FileSessionStore{f: f, sid: sid, values: kv} 110 ss := &FileSessionStore{f: f, sid: sid, values: kv}
112 return ss, nil 111 return ss, nil
113 } 112 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!