summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2026-05-09 15:26:07 +0900
committernagachika <nagachika@ruby-lang.org>2026-05-09 15:26:33 +0900
commit55f7432b303c70f2f0ee6fa4659f6a366292dc3e (patch)
tree0d6f0a8d269adcbb5153c1dc0fb85af209416071
parentde535e907196bbd1198dbd69523f4eef18bdd133 (diff)
Bump pstore version to v0.2.1. [Bug #21880]ruby_3_4
-rw-r--r--lib/pstore.rb25
-rw-r--r--test/test_pstore.rb13
-rw-r--r--version.h2
3 files changed, 28 insertions, 12 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index fdb5e26094..932de1aef9 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -326,11 +326,14 @@ require "digest"
# end
#
class PStore
- VERSION = "0.1.4"
+ # :stopdoc:
+ VERSION = "0.2.1"
RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
+ private_constant :RDWR_ACCESS, :RD_ACCESS, :WR_ACCESS
+ # :startdoc:
# The error type thrown by all PStore methods.
class Error < StandardError
@@ -591,6 +594,8 @@ class PStore
end
private
+ # :stopdoc:
+
# Constant for relieving Ruby's garbage collector.
CHECKSUM_ALGO = %w[SHA512 SHA384 SHA256 SHA1 RMD160 MD5].each do |algo|
begin
@@ -602,6 +607,10 @@ class PStore
EMPTY_MARSHAL_DATA = Marshal.dump({})
EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)
+ EMPTY_MARSHAL_DATA.freeze
+ EMPTY_MARSHAL_CHECKSUM.freeze
+ private_constant :CHECKSUM_ALGO, :EMPTY_STRING, :EMPTY_MARSHAL_DATA, :EMPTY_MARSHAL_CHECKSUM
+
#
# Open the specified filename (either in read-only mode or in
# read-write mode) and lock it for reading or writing.
@@ -664,20 +673,16 @@ class PStore
end
end
- def on_windows?
- is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
- self.class.__send__(:define_method, :on_windows?) do
- is_windows
- end
- is_windows
- end
+ ON_WINDOWS = true & (/mswin|mingw|bccwin|wince/ =~ RUBY_PLATFORM) # :nodoc:
+ private_constant :ON_WINDOWS
def save_data(original_checksum, original_file_size, file)
new_data = dump(@table)
if new_data.bytesize != original_file_size || CHECKSUM_ALGO.digest(new_data) != original_checksum
- if @ultra_safe && !on_windows?
- # Windows doesn't support atomic file renames.
+ if @ultra_safe && !ON_WINDOWS
+ # Once a file is locked, Windows does not guarantee that the
+ # lock will be released until the file is closed.
save_data_with_atomic_file_rename_strategy(new_data, file)
else
save_data_with_fast_strategy(new_data, file)
diff --git a/test/test_pstore.rb b/test/test_pstore.rb
index 7dfbdca367..4a65e4fec9 100644
--- a/test/test_pstore.rb
+++ b/test/test_pstore.rb
@@ -66,6 +66,16 @@ class PStoreTest < Test::Unit::TestCase
end
end
+ def test_data_should_be_stored_correctly_when_in_ultra_safe_mode
+ @pstore.ultra_safe = true
+ @pstore.transaction do
+ @pstore[:foo] = "bar"
+ end
+ @pstore.transaction(true) do
+ assert_equal "bar", @pstore[:foo]
+ end
+ end
+
def test_writing_inside_readonly_transaction_raises_error
assert_raise(PStore::Error) do
@pstore.transaction(true) do
@@ -133,7 +143,8 @@ class PStoreTest < Test::Unit::TestCase
def test_pstore_files_are_accessed_as_binary_files
bug5311 = '[ruby-core:39503]'
n = 128
- assert_in_out_err(["-Eutf-8:utf-8", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 30)
+ top_dir = File.expand_path('../lib', __dir__)
+ assert_in_out_err(["-Eutf-8:utf-8", "-I#{top_dir}", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 30)
@pstore = PStore.new(ARGV[0])
(1..#{n}).each do |i|
@pstore.transaction {@pstore["Key\#{i}"] = "value \#{i}"}
diff --git a/version.h b/version.h
index 0796278b85..432b5f2f44 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 9
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 86
+#define RUBY_PATCHLEVEL 87
#include "ruby/version.h"
#include "ruby/internal/abi.h"