summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-02-16 12:37:18 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-03-26 08:42:02 +0900
commit59a72538b6aa26a5fcfa09b213097d74f5f567c8 (patch)
treec405d9a9fb85d4e1563076d7dcd8e10c535fc8cd
parentc26c0e3824811666a18cb5c21a3c690161b35930 (diff)
[ruby/pstore] Define the platform constant
Rather than overwriting the predicate method dynamically. Fix [Bug #21880](https://bugs.ruby-lang.org/issues/21880). https://github.com/ruby/pstore/commit/b2e474e619
-rw-r--r--lib/pstore.rb17
-rw-r--r--test/test_pstore.rb10
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 8f17c11d7d..1ec776e504 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -667,23 +667,16 @@ class PStore
end
end
- def on_windows?
- is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
-
- on_windows_proc = Proc.new do
- is_windows
- end
- Ractor.make_shareable(on_windows_proc) if defined?(Ractor)
- self.class.__send__(:define_method, :on_windows?, &on_windows_proc)
- 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 696660bd0f..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