From 59a72538b6aa26a5fcfa09b213097d74f5f567c8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 16 Feb 2026 12:37:18 +0900 Subject: [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 --- lib/pstore.rb | 17 +++++------------ test/test_pstore.rb | 10 ++++++++++ 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 -- cgit v1.2.3