summaryrefslogtreecommitdiffstats
path: root/lib/session.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-12-31 16:54:40 +0000
committerTed Trask <ttrask01@yahoo.com>2008-12-31 16:54:40 +0000
commit7ce6cccc867f1f26cd757393be43637cf03c7264 (patch)
treeeb24fcd419bd139725ac7c4ab9b39c9a066a52fc /lib/session.lua
parent37eb227f96b84cfadcc707662f3ccf0e16010b9d (diff)
downloadacf-core-7ce6cccc867f1f26cd757393be43637cf03c7264.tar.bz2
acf-core-7ce6cccc867f1f26cd757393be43637cf03c7264.tar.xz
Workaround in session.lua for simultaneous access with same session id resulting in clearing the session data.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1656 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/session.lua')
-rw-r--r--lib/session.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/session.lua b/lib/session.lua
index a48b293..dd56c86 100644
--- a/lib/session.lua
+++ b/lib/session.lua
@@ -100,17 +100,21 @@ save_session = function( sessionpath, sessiontable)
sessiontable.id = nil
-- If the table only has an "id" field, then don't save it
- if #sessiontable then
+ if #sessiontable then
+ local output = {}
+ output[#output+1] = "-- This is an ACF session table."
+ output[#output+1] = "local " .. serialize("s", sessiontable)
+ output[#output+1] = "return s"
+
local file = io.open(sessionpath .. "/session." .. id , "w")
if file == nil then
sessiontable.id=id
return false
end
- file:write ( "-- This is an ACF session table.\n")
- file:write ( "\nlocal " )
- file:write ( serialize("s", sessiontable) )
- file:write ( "return s\n")
+ for i,out in ipairs(output) do
+ file:write(out, "\n")
+ end
file:close()
end
@@ -133,7 +137,21 @@ load_session = function ( sessionpath, session )
local spath = sessionpath .. "/session." .. session
local ts = posix.stat(spath, "ctime")
if (ts) then
- s = dofile(spath) or {}
+ -- this loop is here because can't read file here if another process is writing it above
+ -- and if this fails, it effectively logs the user off (writes back blank session data)
+ local s
+ for i=1,20 do
+ local file = io.open(spath)
+ if file then
+ local content = file:read("*a")
+ file:close()
+ s = loadstring(content)()
+ break
+ end
+ sleep(10*i)
+ end
+
+ s = s or {}
s.id = session
return ts, s
else