@@ -189,6 +189,47 @@ def create_new_id
189
189
end
190
190
private :create_new_id
191
191
192
+
193
+ # Create a new file to store the session data.
194
+ #
195
+ # This file will be created if it does not exist, or opened if it
196
+ # does.
197
+ #
198
+ # This path is generated under _tmpdir_ from _prefix_, the
199
+ # digested session id, and _suffix_.
200
+ #
201
+ # +option+ is a hash of options for the initializer. The
202
+ # following options are recognised:
203
+ #
204
+ # tmpdir:: the directory to use for storing the FileStore
205
+ # file. Defaults to Dir::tmpdir (generally "/tmp"
206
+ # on Unix systems).
207
+ # prefix:: the prefix to add to the session id when generating
208
+ # the filename for this session's FileStore file.
209
+ # Defaults to "cgi_sid_".
210
+ # suffix:: the prefix to add to the session id when generating
211
+ # the filename for this session's FileStore file.
212
+ # Defaults to the empty string.
213
+ def new_store_file ( option = { } ) # :nodoc:
214
+ dir = option [ 'tmpdir' ] || Dir ::tmpdir
215
+ prefix = option [ 'prefix' ]
216
+ suffix = option [ 'suffix' ]
217
+ require 'digest/md5'
218
+ md5 = Digest ::MD5 . hexdigest ( session_id ) [ 0 , 16 ]
219
+ path = dir +"/"
220
+ path << prefix if prefix
221
+ path << md5
222
+ path << suffix if suffix
223
+ if File ::exist? path
224
+ hash = nil
225
+ elsif new_session
226
+ hash = { }
227
+ else
228
+ raise NoSession , "uninitialized session"
229
+ end
230
+ return path , hash
231
+ end
232
+
192
233
# Create a new CGI::Session object for +request+.
193
234
#
194
235
# +request+ is an instance of the +CGI+ class (see cgi.rb).
@@ -373,21 +414,8 @@ class FileStore
373
414
# This session's FileStore file will be created if it does
374
415
# not exist, or opened if it does.
375
416
def initialize ( session , option = { } )
376
- dir = option [ 'tmpdir' ] || Dir ::tmpdir
377
- prefix = option [ 'prefix' ] || 'cgi_sid_'
378
- suffix = option [ 'suffix' ] || ''
379
- id = session . session_id
380
- require 'digest/md5'
381
- md5 = Digest ::MD5 . hexdigest ( id ) [ 0 , 16 ]
382
- @path = dir +"/" +prefix +md5 +suffix
383
- if File ::exist? @path
384
- @hash = nil
385
- else
386
- unless session . new_session
387
- raise CGI ::Session ::NoSession , "uninitialized session"
388
- end
389
- @hash = { }
390
- end
417
+ option = { 'prefix' => 'cgi_sid_' } . update ( option )
418
+ @path , @hash = session . new_store_file ( option )
391
419
end
392
420
393
421
# Restore session state from the session's FileStore file.
0 commit comments