higgs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/ChangeLog +208 -0
  2. data/LICENSE +26 -0
  3. data/README +2 -0
  4. data/Rakefile +75 -0
  5. data/bin/higgs_backup +67 -0
  6. data/bin/higgs_dump_index +43 -0
  7. data/bin/higgs_dump_jlog +42 -0
  8. data/bin/higgs_verify +37 -0
  9. data/lib/cgi/session/higgs.rb +72 -0
  10. data/lib/higgs/block.rb +192 -0
  11. data/lib/higgs/cache.rb +117 -0
  12. data/lib/higgs/dbm.rb +55 -0
  13. data/lib/higgs/exceptions.rb +31 -0
  14. data/lib/higgs/flock.rb +77 -0
  15. data/lib/higgs/index.rb +164 -0
  16. data/lib/higgs/jlog.rb +159 -0
  17. data/lib/higgs/lock.rb +189 -0
  18. data/lib/higgs/storage.rb +1086 -0
  19. data/lib/higgs/store.rb +228 -0
  20. data/lib/higgs/tar.rb +390 -0
  21. data/lib/higgs/thread.rb +370 -0
  22. data/lib/higgs/tman.rb +513 -0
  23. data/lib/higgs/utils/bman.rb +285 -0
  24. data/lib/higgs/utils.rb +22 -0
  25. data/lib/higgs/version.rb +21 -0
  26. data/lib/higgs.rb +59 -0
  27. data/misc/cache_bench/cache_bench.rb +43 -0
  28. data/misc/dbm_bench/.strc +8 -0
  29. data/misc/dbm_bench/Rakefile +78 -0
  30. data/misc/dbm_bench/dbm_multi_thread.rb +199 -0
  31. data/misc/dbm_bench/dbm_rnd_delete.rb +43 -0
  32. data/misc/dbm_bench/dbm_rnd_read.rb +44 -0
  33. data/misc/dbm_bench/dbm_rnd_update.rb +44 -0
  34. data/misc/dbm_bench/dbm_seq_read.rb +45 -0
  35. data/misc/dbm_bench/dbm_seq_write.rb +44 -0
  36. data/misc/dbm_bench/st_verify.rb +28 -0
  37. data/misc/io_bench/cksum_bench.rb +48 -0
  38. data/misc/io_bench/jlog_bench.rb +71 -0
  39. data/misc/io_bench/write_bench.rb +128 -0
  40. data/misc/thread_bench/lock_bench.rb +132 -0
  41. data/mkrdoc.rb +8 -0
  42. data/rdoc.yml +13 -0
  43. data/sample/count.rb +60 -0
  44. data/sample/dbmtest.rb +38 -0
  45. data/test/Rakefile +45 -0
  46. data/test/run.rb +32 -0
  47. data/test/test_block.rb +163 -0
  48. data/test/test_cache.rb +214 -0
  49. data/test/test_cgi_session.rb +142 -0
  50. data/test/test_flock.rb +162 -0
  51. data/test/test_index.rb +258 -0
  52. data/test/test_jlog.rb +180 -0
  53. data/test/test_lock.rb +320 -0
  54. data/test/test_online_backup.rb +169 -0
  55. data/test/test_storage.rb +439 -0
  56. data/test/test_storage_conf.rb +202 -0
  57. data/test/test_storage_init_opts.rb +89 -0
  58. data/test/test_store.rb +211 -0
  59. data/test/test_tar.rb +432 -0
  60. data/test/test_thread.rb +541 -0
  61. data/test/test_tman.rb +875 -0
  62. data/test/test_tman_init_opts.rb +56 -0
  63. data/test/test_utils_bman.rb +234 -0
  64. metadata +115 -0
data/ChangeLog ADDED
@@ -0,0 +1,208 @@
1
+ 2007-09-29 TOKI Yoshinori <toki@freedom.ne.jp>
2
+
3
+ * lib/higgs/version.rb: version 0.1.0.
4
+
5
+ * check ruby-1.8.6-p110
6
+ ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-linux], OK.
7
+ ruby 1.8.6 (2007-09-23 patchlevel 110) [i386-cygwin], OK.
8
+
9
+ 2007-09-28 TOKI Yoshinori <toki@freedom.ne.jp>
10
+
11
+ * started subversion repository on rubyforge.org.
12
+
13
+ * add document utilities for package.
14
+
15
+ 2007-09-26 TOKI Yoshinori <toki@freedom.ne.jp>
16
+
17
+ * Source Code Management: cvs -> svn.
18
+
19
+ 2007-09-24 TOKI Yoshinori <toki@freedom.ne.jp>
20
+
21
+ * lib/higgs/version.rb: version 0.0.6.
22
+
23
+ * LICENSE: BSD style license.
24
+
25
+ * lib/higgs/storage.rb (Higgs::Storage class): fix a bug of
26
+ auto-recovery at the read-write open.
27
+
28
+ 2007-09-18 TOKI Yoshinori <toki@freedom.ne.jp>
29
+
30
+ * lib/higgs/storage.rb (Higgs::Storage class): strict check for
31
+ recovery.
32
+
33
+ 2007-09-17 TOKI Yoshinori <toki@freedom.ne.jp>
34
+
35
+ * sample/count.rb: sample of Higgs::Store
36
+
37
+ 2007-09-09 TOKI Yoshinori <toki@freedom.ne.jp>
38
+
39
+ * lib/higgs/tman.rb (Higgs::TransactionContext class): update
40
+ secondary cache on writing.
41
+
42
+ * lib/higgs/cache.rb (Higgs::SharedWorkCache class): update for
43
+ cache entry.
44
+
45
+ * lib/higgs/thread.rb (Higgs::SharedWork class): update for
46
+ result.
47
+
48
+ 2007-08-29 TOKI Yoshinori <toki@freedom.ne.jp>
49
+
50
+ * lib/higgs/tman.rb: update method.
51
+
52
+ 2007-08-26 TOKI Yoshinori <toki@freedom.ne.jp>
53
+
54
+ * lib/higgs/tman.rb: current transaction access in a thread.
55
+
56
+ 2007-08-07 TOKI Yoshinori <toki@freedom.ne.jp>
57
+
58
+ * lib/higgs/tman.rb: secondary cache.
59
+
60
+ 2007-08-05 TOKI Yoshinori <toki@freedom.ne.jp>
61
+
62
+ * lib/higgs/index.rb: identities for key of secondary cache.
63
+
64
+ * cvs tag of higgs_snapshot_20070805. snapshot before secondary
65
+ cache implementation.
66
+
67
+ 2007-07-28 TOKI Yoshinori <toki@freedom.ne.jp>
68
+
69
+ * lib/higgs/version.rb: version 0.0.5.
70
+
71
+ * bin/higgs_backup: backup utility.
72
+
73
+ 2007-07-24 TOKI Yoshinori <toki@freedom.ne.jp>
74
+
75
+ * lib/higgs/utils/bman.rb: online backup scenario.
76
+
77
+ 2007-07-23 TOKI Yoshinori <toki@freedom.ne.jp>
78
+
79
+ * test/test_utils_bman.rb: unit test for backup manager.
80
+
81
+ * lib/higgs/utils/bman.rb: backup manager.
82
+
83
+ * lib/higgs/utils.rb: namespace for higgs utilities.
84
+
85
+ 2007-07-16 TOKI Yoshinori <toki@freedom.ne.jp>
86
+
87
+ * lib/higgs/storage.rb: load storage options from YAML
88
+ configuration file.
89
+
90
+ * lib/higgs/tman.rb: new Higgs::TransactionManager::Export
91
+ module. export transaction manager methods from @tman instance
92
+ variable.
93
+
94
+ 2007-07-15 TOKI Yoshinori <toki@freedom.ne.jp>
95
+
96
+ * lib/higgs/storage.rb: new Higgs::Storage::Export module. export
97
+ storage methods from @storage instance variable.
98
+
99
+ * lib/cgi/session/higgs.rb, lib/higgs.rb, lib/higgs/block.rb,
100
+ lib/higgs/cache.rb, lib/higgs/dbm.rb, lib/higgs/exceptions.rb,
101
+ lib/higgs/flock.rb, lib/higgs/index.rb, lib/higgs/jlog.rb,
102
+ lib/higgs/lock.rb, lib/higgs/storage.rb, lib/higgs/store.rb,
103
+ lib/higgs/tar.rb, lib/higgs/thread.rb, lib/higgs/tman.rb: some
104
+ rdoc comments.
105
+
106
+ * lib/higgs/storage.rb: change confusing error name:
107
+ Higgs::Storage::BrokenError (alike Higgs::Block::BrokenError) ->
108
+ Higgs::Storage::PanicError.
109
+
110
+ * bin/higgs_verify: command line options.
111
+
112
+ 2007-07-12 TOKI Yoshinori <toki@freedom.ne.jp>
113
+
114
+ * lib/higgs/storage.rb: change journal log format.
115
+
116
+ * lib/higgs/version.rb: version 0.0.4.
117
+
118
+ 2007-07-11 TOKI Yoshinori <toki@freedom.ne.jp>
119
+
120
+ * bin/higgs_dump_index, bin/higgs_dump_jlog: command line options.
121
+
122
+ 2007-07-10 TOKI Yoshinori <toki@freedom.ne.jp>
123
+
124
+ * lib/higgs/tman.rb: decode or freeze in each transaction for the rollback.
125
+
126
+ 2007-07-08 TOKI Yoshinori <toki@freedom.ne.jp>
127
+
128
+ * bin/higgs_dump_index, bin/higgs_dump_jlog, bin/higgs_verify:
129
+ tools.
130
+
131
+ * lib/higgs/version.rb: version 0.0.3.
132
+
133
+ 2007-07-07 TOKI Yoshinori <toki@freedom.ne.jp>
134
+
135
+ * lib/higgs/storage.rb: new `string_only' system property.
136
+
137
+ 2007-07-05 TOKI Yoshinori <toki@freedom.ne.jp>
138
+
139
+ * lib/higgs/version.rb: version 0.0.2.
140
+
141
+ * lib/higgs/tman.rb: clear local properties cache on new write.
142
+
143
+ 2007-07-04 TOKI Yoshinori <toki@freedom.ne.jp>
144
+
145
+ * lib/higgs/version.rb: version description file.
146
+
147
+ * lib/higgs/tman.rb: clear local properties cache on new write.
148
+
149
+ 2007-06-23 TOKI Yoshinori <toki@freedom.ne.jp>
150
+
151
+ * lib/higgs/storage.rb: unique free block name.
152
+
153
+ 2007-06-07 TOKI Yoshinori <toki@freedom.ne.jp>
154
+
155
+ * Rakefile: gem package task.
156
+
157
+ 2007-05-21 TOKI Yoshinori <toki@freedom.ne.jp>
158
+
159
+ * lib/higgs/storage.rb: various data cksum type.
160
+
161
+ * lib/higgs/block.rb, lib/higgs/jlog.rb: various block body cksum
162
+ type.
163
+
164
+ 2007-05-19 TOKI Yoshinori <toki@freedom.ne.jp>
165
+
166
+ * lib/cgi/session/higgs.rb: for CGI session.
167
+
168
+ 2007-05-16 TOKI Yoshinori <toki@freedom.ne.jp>
169
+
170
+ * lib/higgs/storage.rb (Higgs::Storage): cancel of initialization on fail.
171
+
172
+ 2007-05-14 TOKI Yoshinori <toki@freedom.ne.jp>
173
+
174
+ * lib/higgs/storage.rb (Higgs::Storage): fix a bug of
175
+ raw_write_and_commit.
176
+
177
+ 2007-05-07 TOKI Yoshinori <toki@freedom.ne.jp>
178
+
179
+ * lib/higgs/storage.rb (Higgs::Storage): check index change number
180
+ in journal log.
181
+
182
+ 2007-05-06 TOKI Yoshinori <toki@freedom.ne.jp>
183
+
184
+ * test/optional/test_online_backup.rb: online backup test.
185
+
186
+ * indentation tab -> white spaces.
187
+
188
+ * lib/higgs/jlog.rb (Higgs::JournalLogger): optional eof flag to
189
+ close method.
190
+
191
+ * lib/higgs/tar.rb (Higgs::Tar::ArchiveWriter): reverse optional
192
+ flag of close method.
193
+
194
+ * lib/higgs/tman.rb (Higgs::TransactionContext): allow to store
195
+ nil value to local data cache.
196
+
197
+ 2007-05-04 TOKI Yoshinori <toki@freedom.ne.jp>
198
+
199
+ * lib/higgs/thread.rb: obsolete name space: Higgs::Thread
200
+
201
+ * lib/higgs/lock.rb: obsolete name space: Higgs::Lock
202
+
203
+ * lib/higgs/cache.rb: obsolete name space: Higgs::Cache
204
+
205
+ * merge from development branch:
206
+ cvs update -j higgs_snapshot_20070420 -j higgs_snapshot_20070420_branch_20070420_snapshot_20070504
207
+
208
+
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2007
2
+ TOKI Yoshinori <toki@freedom.ne.jp>. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20
+ SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26
+ OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,2 @@
1
+ please run `ruby mkrdoc.rb' or `rake rdoc', and see api/index.html by
2
+ your browser.
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ # for ident(1)
2
+ CVS_ID = '$Id: Rakefile 576 2007-09-29 08:35:19Z toki $'
3
+
4
+ require 'lib/higgs/version'
5
+ require 'rake/gempackagetask'
6
+ require 'yaml'
7
+
8
+ LIB_DIR = 'lib'
9
+ TEST_DIR = 'test'
10
+ RDOC_DIR = 'api'
11
+ RDOC_MAIN = 'Higgs'
12
+
13
+ def cd_v(dir)
14
+ cd(dir, :verbose => true) {
15
+ yield
16
+ }
17
+ end
18
+
19
+ def load_rdoc_opts
20
+ YAML.load(IO.read('rdoc.yml'))
21
+ end
22
+
23
+ task :default
24
+
25
+ task :test do
26
+ cd_v TEST_DIR do
27
+ sh 'rake'
28
+ end
29
+ end
30
+
31
+ task :rdoc do
32
+ rdoc_opts = load_rdoc_opts
33
+ sh 'rdoc', *(rdoc_opts['CommonOptions'] + rdoc_opts['CommandLineOptions']).flatten
34
+ end
35
+
36
+ task :rdoc_clean do
37
+ rm_rf RDOC_DIR
38
+ end
39
+
40
+ task :rdoc_upload => [ :rdoc_clean, :rdoc ] do
41
+ sh 'scp', '-pr', RDOC_DIR, 'rubyforge.org:/var/www/gforge-projects/higgs/.'
42
+ end
43
+
44
+ spec = Gem::Specification.new{|s|
45
+ s.name = 'higgs'
46
+ s.version = Higgs::VERSION
47
+ s.summary = 'pure ruby transactional storage compatible with unix TAR format'
48
+ s.author = 'TOKI Yoshinori'
49
+ s.email = 'toki@freedom.ne.jp'
50
+ s.executables = %w[ higgs_backup higgs_dump_index higgs_dump_jlog higgs_verify ]
51
+ s.files = Dir['**/{Rakefile,.strc,*.{rb,yml}}']
52
+ s.files += %w[ ChangeLog LICENSE README ]
53
+ s.test_files = %w[ test/run.rb ]
54
+ s.has_rdoc = true
55
+ s.rdoc_options = load_rdoc_opts['CommonOptions'].flatten
56
+ }
57
+ Rake::GemPackageTask.new(spec) do |pkg|
58
+ pkg.need_zip = true
59
+ pkg.need_tar_gz = true
60
+ end
61
+
62
+ task :gem_install => [ :gem ] do
63
+ sh 'gem', 'install', "pkg/higgs-#{Higgs::VERSION}.gem"
64
+ end
65
+
66
+ task :clean => [ :rdoc_clean, :clobber_package ] do
67
+ cd_v 'misc/dbm_bench' do
68
+ sh 'rake', 'clean'
69
+ end
70
+ end
71
+
72
+ # Local Variables:
73
+ # mode: Ruby
74
+ # indent-tabs-mode: nil
75
+ # End:
data/bin/higgs_backup ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'higgs/utils/bman'
4
+ require 'optparse'
5
+
6
+ # for ident(1)
7
+ CVS_ID = '$Id: higgs_backup 546 2007-09-23 14:20:23Z toki $'
8
+
9
+ STDOUT.sync = true
10
+
11
+ opts = OptionParser.new
12
+ opts.banner = "Usage: #{opts.program_name} [options]"
13
+
14
+ command = :online_backup
15
+ options = { :verbose => 0 }
16
+
17
+ opts.on('--command=BACKUP_COMMAND',
18
+ [ :index, :data, :rotate, :jlog, :recover, :verify, :clean, :online_backup ]) {|value|
19
+ command = value
20
+ }
21
+
22
+ opts.on('-f', '--from=BACKUP_TARGET_STORAGE', String) {|value|
23
+ options[:from] = value
24
+ }
25
+ opts.on('-t', '--to-dir=DIR_TO_BACKUP', String) {|value|
26
+ options[:to_dir] = value
27
+ }
28
+ opts.on('-n', '--to-name=NAME_TO_BACKUP', String) {|value|
29
+ options[:to_name] = value
30
+ }
31
+ opts.on('-u', '--jlog-rotate-service-uri=URI', String) {|value|
32
+ options[:jlog_rotate_service_uri] = value
33
+ }
34
+ opts.on('-v', '--verbose', '--[no-]verbose') {|value|
35
+ if (value) then
36
+ options[:verbose] += 1
37
+ else
38
+ options[:verbose] -= 1
39
+ end
40
+ }
41
+ opts.on('--verbose-level=LEVEL', Integer) {|value|
42
+ options[:verbose] = value
43
+ }
44
+
45
+ opts.parse!
46
+ bman = Higgs::Utils::BackupManager.new(options)
47
+
48
+ case (command)
49
+ when :online_backup
50
+ bman.online_backup
51
+ when :index
52
+ bman.backup_index
53
+ when :data
54
+ bman.backup_data
55
+ when :rotate
56
+ bman.rotate_jlog
57
+ when :jlog
58
+ bman.backup_jlog
59
+ when :recover
60
+ bman.recover
61
+ when :verify
62
+ bman.verify
63
+ when :clean
64
+ bman.clean_jlog
65
+ else
66
+ raise "unknown backup command: #{command}"
67
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'higgs/index'
4
+ require 'optparse'
5
+ require 'pp'
6
+ require 'yaml'
7
+
8
+ # for ident(1)
9
+ CVS_ID = '$Id: higgs_dump_index 462 2007-07-15 09:25:07Z toki $'
10
+
11
+ opts = OptionParser.new
12
+ opts.banner = "Usage: #{opts.program_name} [options] INDEX_PATH"
13
+
14
+ output_format = :pretty
15
+ opts.on('-o', '--output-format=FORMAT', [ :pretty, :yaml ]) {|value|
16
+ output_format = value
17
+ }
18
+
19
+ opts.on_tail('-h', '--help') {
20
+ puts opts
21
+ puts 'Output format:'
22
+ print opts.summary_indent, :pretty, "\n"
23
+ print opts.summary_indent, :yaml, "\n"
24
+ exit(1)
25
+ }
26
+ opts.parse!
27
+
28
+ index = Higgs::Index.new
29
+ index.load(ARGV[0])
30
+
31
+ case (output_format)
32
+ when :pretty
33
+ pp index
34
+ when :yaml
35
+ puts index.to_yaml
36
+ else
37
+ raise "unknown output format: #{output_format}"
38
+ end
39
+
40
+ # Local Variables:
41
+ # mode: Ruby
42
+ # indent-tabs-mode: nil
43
+ # End:
@@ -0,0 +1,42 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'higgs/jlog'
4
+ require 'optparse'
5
+ require 'pp'
6
+ require 'yaml'
7
+
8
+ # for ident(1)
9
+ CVS_ID = '$Id: higgs_dump_jlog 462 2007-07-15 09:25:07Z toki $'
10
+
11
+ opts = OptionParser.new
12
+ opts.banner = "Usage: #{opts.program_name} [options] [JOURNAL_LOG_PATHs]"
13
+
14
+ output_format = :pretty
15
+ opts.on('-o', '--output-format=FORMAT', [ :pretty, :yaml ]) {|value|
16
+ output_format = value
17
+ }
18
+
19
+ opts.on_tail('-h', '--help') {
20
+ puts opts
21
+ puts 'Output format:'
22
+ print opts.summary_indent, :pretty, "\n"
23
+ print opts.summary_indent, :yaml, "\n"
24
+ exit(1)
25
+ }
26
+ opts.parse!
27
+
28
+ Higgs::JournalLogger.scan_log(ARGF) {|log|
29
+ case (output_format)
30
+ when :pretty
31
+ pp log
32
+ when :yaml
33
+ puts log.to_yaml
34
+ else
35
+ raise "unknown output format: #{output_format}"
36
+ end
37
+ }
38
+
39
+ # Local Variables:
40
+ # mode: Ruby
41
+ # indent-tabs-mode: nil
42
+ # End:
data/bin/higgs_verify ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'higgs/storage'
4
+ require 'optparse'
5
+
6
+ # for ident(1)
7
+ CVS_ID = '$Id: higgs_verify 463 2007-07-15 09:52:12Z toki $'
8
+
9
+ opts = OptionParser.new
10
+ opts.banner = "Usage: #{opts.program_name} [options] HIGGS_NAME"
11
+
12
+ verbose_level = 0
13
+ opts.on('-v', '--[no-]verbose') {|v|
14
+ if (v) then
15
+ verbose_level += 1
16
+ else
17
+ verbose_level -= 1
18
+ end
19
+ }
20
+ opts.on('--verbose-level=LEVEL', Integer) {|level|
21
+ verbose_level = level
22
+ }
23
+
24
+ opts.parse!
25
+ higgs_name = ARGV.shift or raise 'requried HIGGS_PATH'
26
+
27
+ st = Higgs::Storage.new(higgs_name, :read_only => true)
28
+ begin
29
+ st.verify(STDOUT, verbose_level)
30
+ ensure
31
+ st.shutdown
32
+ end
33
+
34
+ # Local Variables:
35
+ # mode: Ruby
36
+ # indent-tabs-mode: nil
37
+ # End:
@@ -0,0 +1,72 @@
1
+ # like cgi/session/pstore.rb
2
+ #
3
+ # Author:: $Author: toki $
4
+ # Date:: $Date: 2007-09-26 00:20:20 +0900 (Wed, 26 Sep 2007) $
5
+ # Revision:: $Revision: 559 $
6
+ #
7
+
8
+ require 'cgi/session'
9
+ require 'digest/md5'
10
+ require 'fileutils'
11
+ require 'higgs/store'
12
+
13
+ class CGI
14
+ class Session
15
+ # like cgi/session/pstore.rb
16
+ class HiggsStore
17
+ # for ident(1)
18
+ CVS_ID = '$Id: higgs.rb 559 2007-09-25 15:20:20Z toki $'
19
+
20
+ def initialize(session, options={})
21
+ dir = options['tmpdir'] || Dir.tmpdir
22
+ prefix = options['prefix'] || ''
23
+ id = session.session_id
24
+ name = options['name'] || 'session'
25
+ md5 = Digest::MD5.hexdigest(id)
26
+ @store_dir = File.join(dir, prefix + md5)
27
+ FileUtils.mkdir_p(@store_dir)
28
+ @store_path = File.join(@store_dir, name)
29
+ @store_path.untaint
30
+ if (File.exist? "#{@store_path}.lock") then
31
+ @hash = nil
32
+ else
33
+ unless (session.new_session) then
34
+ raise CGI::Session::NoSession, 'uninitialized session'
35
+ end
36
+ @hash = {}
37
+ end
38
+ @store = Higgs::Store.new(@store_path, options)
39
+ end
40
+
41
+ def restore
42
+ unless (@hash) then
43
+ @store.transaction{|tx|
44
+ @hash = tx[:hash] || {}
45
+ }
46
+ end
47
+ @hash
48
+ end
49
+
50
+ def update
51
+ @store.transaction{|tx|
52
+ tx[:hash] = @hash
53
+ }
54
+ end
55
+
56
+ def close
57
+ r = nil
58
+ unless (@store.shutdown?) then
59
+ r = update
60
+ @store.shutdown
61
+ end
62
+ r
63
+ end
64
+
65
+ def delete
66
+ @store.shutdown unless @store.shutdown?
67
+ FileUtils.rm_rf(@store_dir)
68
+ nil
69
+ end
70
+ end
71
+ end
72
+ end