[Ruby-session-devel-cvs] CVS: ruby-session/src/apache/session file.rb,NONE,1.1
Status: Alpha
Brought to you by:
thetitan
From: Sean C. <the...@us...> - 2001-08-25 10:31:54
|
Update of /cvsroot/ruby-session/ruby-session/src/apache/session In directory usw-pr-cvs1:/tmp/cvs-serv2396/src/apache/session Added Files: file.rb Log Message: Checking in initial work for ruby-session. Has support for file based sessions. Status: functional --- NEW FILE: file.rb --- #!/usr/local/bin/ruby -w # ruby-session: Got persistance? # Copyright 2001 # Sean Chittenden <se...@ch...>. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # # This product includes software developed by Sean Chittenden # <se...@ch...> and ruby-tmpl's contributors. # # 4. Neither the name of the software nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Please see the LICENSE file for more information regarding the use # and distribution of this software. # # $Id: file.rb,v 1.1 2001/08/25 10:31:52 thetitan Exp $ module Apache class Session public protected def make_location () @location = File.join(@session_dir, ".ruby-session-#{@session_id}") return(@location) end def _delete () begin File.delete(@location) rescue Errno::ENOENT raise RuntimeError, "Unable to delete session #{@session_id}" end end def _persist () self.make_location() unless(@location) begin f = File.new(@location, File::CREAT|File::TRUNC|File::WRONLY|File::EXCL, 0600) Marshal.dump(@data, f) f.close() rescue Errno::EEXIST self.restore f = File.new(@location, File::TRUNC|File::WRONLY, 0600) Marshal.dump(@data, f) f.close() end end # End: def _persist () def _restore () begin f = File.new(@location, File::RDONLY) @data.update(Marshal.load(f)) f.close rescue Errno::ENOENT raise RuntimeError, "Can not restore session '#{@session_id}': session does not valid" end end # End: def _restore () private end # End: module Session end # End: module Apache |