summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Kisiel <kamil@kamilkisiel.net>2015-03-26 03:08:44 +0300
committerKamil Kisiel <kamil@kamilkisiel.net>2015-03-26 03:08:44 +0300
commitc8fb5963af5ff7fda6a44132ba4c0d8376e20257 (patch)
tree1d2fb3ff265cca400af11545c1a00900be596ccd
parent1f45645972a051deb63c8e8e3c594041a6145e35 (diff)
parent9a1a995303506329f3fc682912d3baa7b937a724 (diff)
Merge pull request #43 from StableLib/filesystem
Simplify FilesystemStore save and load.
-rw-r--r--store.go30
1 files changed, 5 insertions, 25 deletions
diff --git a/store.go b/store.go
index b3461b0..13cd1db 100644
--- a/store.go
+++ b/store.go
@@ -6,7 +6,7 @@ package sessions
import (
"encoding/base32"
- "io"
+ "io/ioutil"
"net/http"
"os"
"strings"
@@ -218,38 +218,18 @@ func (s *FilesystemStore) save(session *Session) error {
filename := s.path + "session_" + session.ID
fileMutex.Lock()
defer fileMutex.Unlock()
- fp, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
- if err != nil {
- return err
- }
- defer fp.Close()
- if _, err = fp.Write([]byte(encoded)); err != nil {
- return err
- }
- return nil
+ return ioutil.WriteFile(filename, []byte(encoded), 0600)
}
// load reads a file and decodes its content into session.Values.
func (s *FilesystemStore) load(session *Session) error {
filename := s.path + "session_" + session.ID
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0400)
+ fileMutex.RLock()
+ defer fileMutex.RUnlock()
+ fdata, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
- defer fp.Close()
- var fdata []byte
- buf := make([]byte, 128)
- for {
- var n int
- n, err = fp.Read(buf[0:])
- fdata = append(fdata, buf[0:n]...)
- if err != nil {
- if err == io.EOF {
- break
- }
- return err
- }
- }
if err = securecookie.DecodeMulti(session.Name(), string(fdata),
&session.Values, s.Codecs...); err != nil {
return err