forked from web2py/web2py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes web2py#1309 (and sessions2trash.py, too)
- Loading branch information
Showing
2 changed files
with
27 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
EXPIRATION_MINUTES=60 | ||
DIGITS=('0','1','2','3','4','5','6','7','8','9') | ||
import os, time, stat, cPickle, logging | ||
path = os.path.join(request.folder,'sessions') | ||
|
||
import os, time, stat, logging | ||
from gluon._compat import pickle | ||
|
||
EXPIRATION_MINUTES = 60 | ||
|
||
path = os.path.join(request.folder, 'sessions') | ||
if not os.path.exists(path): | ||
os.mkdir(path) | ||
now = time.time() | ||
for filename in os.listdir(path): | ||
fullpath=os.path.join(path,filename) | ||
if os.path.isfile(fullpath) and filename.startswith(DIGITS): | ||
for path, dirs, files in os.walk(path, topdown=False): | ||
for x in files: | ||
fullpath = os.path.join(path, x) | ||
try: | ||
filetime = os.stat(fullpath)[stat.ST_MTIME] # get it before our io | ||
filetime = os.stat(fullpath)[stat.ST_MTIME] # get it before our io | ||
try: | ||
session_data = cPickle.load(open(fullpath, 'rb+')) | ||
session_data = pickle.load(open(fullpath, 'rb+')) | ||
expiration = session_data['auth']['expiration'] | ||
except: | ||
expiration = EXPIRATION_MINUTES * 60 | ||
if (now - filetime) > expiration: | ||
os.unlink(fullpath) | ||
except: | ||
logging.exception('failure to check %s' % fullpath) | ||
for d in dirs: | ||
dd = os.path.join(path, d) | ||
if not os.listdir(dd): | ||
os.rmdir(dd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters