* lib/cgi/session/pstore.rb: fix indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4b9e885000
commit
f22aabbaee
@ -1,3 +1,7 @@
|
|||||||
|
Sun Nov 9 00:02:01 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi/session/pstore.rb: fix indentation.
|
||||||
|
|
||||||
Sat Nov 8 23:47:45 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
Sat Nov 8 23:47:45 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi/session.rb (FileStore): use marshalized data.
|
* lib/cgi/session.rb (FileStore): use marshalized data.
|
||||||
|
@ -43,55 +43,55 @@ class CGI
|
|||||||
# This session's PStore file will be created if it does
|
# This session's PStore file will be created if it does
|
||||||
# not exist, or opened if it does.
|
# not exist, or opened if it does.
|
||||||
def initialize(session, option={})
|
def initialize(session, option={})
|
||||||
dir = option['tmpdir'] || Dir::tmpdir
|
dir = option['tmpdir'] || Dir::tmpdir
|
||||||
prefix = option['prefix'] || ''
|
prefix = option['prefix'] || ''
|
||||||
id = session.session_id
|
id = session.session_id
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
md5 = Digest::MD5.hexdigest(id)[0,16]
|
md5 = Digest::MD5.hexdigest(id)[0,16]
|
||||||
path = dir+"/"+prefix+md5
|
path = dir+"/"+prefix+md5
|
||||||
path.untaint
|
path.untaint
|
||||||
if File::exist?(path)
|
if File::exist?(path)
|
||||||
@hash = nil
|
@hash = nil
|
||||||
else
|
else
|
||||||
unless session.new_session
|
unless session.new_session
|
||||||
raise CGI::Session::NoSession, "uninitialized session"
|
raise CGI::Session::NoSession, "uninitialized session"
|
||||||
end
|
end
|
||||||
@hash = {}
|
@hash = {}
|
||||||
end
|
end
|
||||||
@p = ::PStore.new(path)
|
@p = ::PStore.new(path)
|
||||||
@p.transaction do |p|
|
@p.transaction do |p|
|
||||||
File.chmod(0600, p.path)
|
File.chmod(0600, p.path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Restore session state from the session's PStore file.
|
# Restore session state from the session's PStore file.
|
||||||
#
|
#
|
||||||
# Returns the session state as a hash.
|
# Returns the session state as a hash.
|
||||||
def restore
|
def restore
|
||||||
unless @hash
|
unless @hash
|
||||||
@p.transaction do
|
@p.transaction do
|
||||||
@hash = @p['hash'] || {}
|
@hash = @p['hash'] || {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@hash
|
@hash
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save session state to the session's PStore file.
|
# Save session state to the session's PStore file.
|
||||||
def update
|
def update
|
||||||
@p.transaction do
|
@p.transaction do
|
||||||
@p['hash'] = @hash
|
@p['hash'] = @hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update and close the session's PStore file.
|
# Update and close the session's PStore file.
|
||||||
def close
|
def close
|
||||||
update
|
update
|
||||||
end
|
end
|
||||||
|
|
||||||
# Close and delete the session's PStore file.
|
# Close and delete the session's PStore file.
|
||||||
def delete
|
def delete
|
||||||
path = @p.path
|
path = @p.path
|
||||||
File::unlink path
|
File::unlink path
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user