diff options
Diffstat (limited to 'vendor/gitea.com')
-rw-r--r-- | vendor/gitea.com/macaron/session/file.go | 8 | ||||
-rw-r--r-- | vendor/gitea.com/macaron/session/memory.go | 12 | ||||
-rw-r--r-- | vendor/gitea.com/macaron/session/mysql/mysql.go | 8 | ||||
-rw-r--r-- | vendor/gitea.com/macaron/session/postgres/postgres.go | 8 |
4 files changed, 27 insertions, 9 deletions
diff --git a/vendor/gitea.com/macaron/session/file.go b/vendor/gitea.com/macaron/session/file.go index 3e575564ee..ce915344fb 100644 --- a/vendor/gitea.com/macaron/session/file.go +++ b/vendor/gitea.com/macaron/session/file.go @@ -133,7 +133,15 @@ func (p *FileProvider) Read(sid string) (_ RawStore, err error) { defer p.lock.RUnlock() var f *os.File + ok := false if com.IsFile(filename) { + modTime, err := com.FileMTime(filename) + if err != nil { + return nil, err + } + ok = (modTime + p.maxlifetime) >= time.Now().Unix() + } + if ok { f, err = os.OpenFile(filename, os.O_RDONLY, 0600) } else { f, err = os.Create(filename) diff --git a/vendor/gitea.com/macaron/session/memory.go b/vendor/gitea.com/macaron/session/memory.go index fbb5b8013f..0769225752 100644 --- a/vendor/gitea.com/macaron/session/memory.go +++ b/vendor/gitea.com/macaron/session/memory.go @@ -96,6 +96,8 @@ type MemProvider struct { // Init initializes memory session provider.
func (p *MemProvider) Init(maxLifetime int64, _ string) error {
p.lock.Lock()
+ p.list = list.New()
+ p.data = make(map[string]*list.Element)
p.maxLifetime = maxLifetime
p.lock.Unlock()
return nil
@@ -120,7 +122,8 @@ func (p *MemProvider) Read(sid string) (_ RawStore, err error) { e, ok := p.data[sid]
p.lock.RUnlock()
- if ok {
+ // Only restore if the session is still alive.
+ if ok && (e.Value.(*MemStore).lastAccess.Unix()+p.maxLifetime) >= time.Now().Unix() {
if err = p.update(sid); err != nil {
return nil, err
}
@@ -130,7 +133,10 @@ func (p *MemProvider) Read(sid string) (_ RawStore, err error) { // Create a new session.
p.lock.Lock()
defer p.lock.Unlock()
-
+ if ok {
+ p.list.Remove(e)
+ delete(p.data, sid)
+ }
s := NewMemStore(sid)
p.data[sid] = p.list.PushBack(s)
return s, nil
@@ -213,5 +219,5 @@ func (p *MemProvider) GC() { }
func init() {
- Register("memory", &MemProvider{list: list.New(), data: make(map[string]*list.Element)})
+ Register("memory", &MemProvider{})
}
diff --git a/vendor/gitea.com/macaron/session/mysql/mysql.go b/vendor/gitea.com/macaron/session/mysql/mysql.go index da5079b24a..af1cd9dd1b 100644 --- a/vendor/gitea.com/macaron/session/mysql/mysql.go +++ b/vendor/gitea.com/macaron/session/mysql/mysql.go @@ -120,18 +120,20 @@ func (p *MysqlProvider) Init(expire int64, connStr string) (err error) { // Read returns raw session store by session ID. func (p *MysqlProvider) Read(sid string) (session.RawStore, error) { + now := time.Now().Unix() var data []byte - err := p.c.QueryRow("SELECT data FROM session WHERE `key`=?", sid).Scan(&data) + expiry := now + err := p.c.QueryRow("SELECT data, expiry FROM session WHERE `key`=?", sid).Scan(&data, &expiry) if err == sql.ErrNoRows { _, err = p.c.Exec("INSERT INTO session(`key`,data,expiry) VALUES(?,?,?)", - sid, "", time.Now().Unix()) + sid, "", now) } if err != nil { return nil, err } var kv map[interface{}]interface{} - if len(data) == 0 { + if len(data) == 0 || expiry+p.expire <= now { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(data) diff --git a/vendor/gitea.com/macaron/session/postgres/postgres.go b/vendor/gitea.com/macaron/session/postgres/postgres.go index c307241a3c..f173021d51 100644 --- a/vendor/gitea.com/macaron/session/postgres/postgres.go +++ b/vendor/gitea.com/macaron/session/postgres/postgres.go @@ -121,18 +121,20 @@ func (p *PostgresProvider) Init(maxlifetime int64, connStr string) (err error) { // Read returns raw session store by session ID. func (p *PostgresProvider) Read(sid string) (session.RawStore, error) { + now := time.Now().Unix() var data []byte - err := p.c.QueryRow("SELECT data FROM session WHERE key=$1", sid).Scan(&data) + expiry := now + err := p.c.QueryRow("SELECT data, expiry FROM session WHERE key=$1", sid).Scan(&data, &expiry) if err == sql.ErrNoRows { _, err = p.c.Exec("INSERT INTO session(key,data,expiry) VALUES($1,$2,$3)", - sid, "", time.Now().Unix()) + sid, "", now) } if err != nil { return nil, err } var kv map[interface{}]interface{} - if len(data) == 0 { + if len(data) == 0 || expiry+p.maxlifetime <= now { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(data) |