From 7202dbe91d7232fedca2c00fabcc6b16ea429ac6 Mon Sep 17 00:00:00 2001 From: lyn1001 Date: Mon, 14 Aug 2023 16:00:39 +0800 Subject: [PATCH] fix build error (cherry picked from commit 8f041e13e5001c7a264ae94cadd09607d149c146) --- ...uire-pathname-from-drop-method-tests.patch | 91 +++++++++++++++++++ ...ve-require-pathname-from-drop-method.patch | 26 ++++++ rubygem-activerecord.spec | 10 +- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method-tests.patch create mode 100644 rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method.patch diff --git a/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method-tests.patch b/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method-tests.patch new file mode 100644 index 0000000..43b38c9 --- /dev/null +++ b/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method-tests.patch @@ -0,0 +1,91 @@ +From e708599c85226e9ad107ebdad09a9e31f1b5388a Mon Sep 17 00:00:00 2001 +From: Nicolas Iragorri Dominguez + +Date: Tue, 27 Dec 2022 01:24:19 +0100 +Subject: [PATCH] [issue-46741] remove `require pathname` from `drop` method + +--- + .../test/cases/tasks/sqlite_rake_test.rb | 42 +++++++------------ + +diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb +index 98257867aa773..9b534b88220bd 100644 +--- a/activerecord/test/cases/tasks/sqlite_rake_test.rb ++++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb +@@ -72,15 +72,17 @@ def test_db_create_with_error_prints_message + + class SqliteDBDropTest < ActiveRecord::TestCase + def setup ++ @root = "/rails/root" + @database = "db_create.sqlite3" ++ @database_root = File.join(@root, @database) + @configuration = { + "adapter" => "sqlite3", + "database" => @database + } +- @path = Class.new do +- def to_s; "/absolute/path" end +- def absolute?; true end +- end.new ++ @configuration_root = { ++ "adapter" => "sqlite3", ++ "database" => @database_root ++ } + + $stdout, @original_stdout = StringIO.new, $stdout + $stderr, @original_stderr = StringIO.new, $stderr +@@ -90,45 +92,33 @@ def teardown + $stdout, $stderr = @original_stdout, @original_stderr + end + +- def test_creates_path_from_database +- assert_called_with(Pathname, :new, [@database], returns: @path) do +- ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" ++ def test_checks_db_dir_is_absolute ++ assert_called_with(File, :absolute_path?, [@database], returns: false) do ++ ActiveRecord::Tasks::DatabaseTasks.drop @configuration, @root + end + end + + def test_removes_file_with_absolute_path +- Pathname.stub(:new, @path) do +- assert_called_with(FileUtils, :rm, ["/absolute/path"]) do +- ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" +- end ++ assert_called_with(FileUtils, :rm, [@database_root]) do ++ ActiveRecord::Tasks::DatabaseTasks.drop @configuration_root, @root + end + end + + def test_generates_absolute_path_with_given_root +- Pathname.stub(:new, @path) do +- @path.stub(:absolute?, false) do +- assert_called_with(File, :join, ["/rails/root", @path], +- returns: "/former/relative/path" +- ) do +- ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" +- end +- end ++ assert_called_with(File, :join, [@root, @database], returns: "#{@root}/#{@database}") do ++ ActiveRecord::Tasks::DatabaseTasks.drop @configuration, @root + end + end + + def test_removes_file_with_relative_path +- File.stub(:join, "/former/relative/path") do +- @path.stub(:absolute?, false) do +- assert_called_with(FileUtils, :rm, ["/former/relative/path"]) do +- ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" +- end +- end ++ assert_called_with(FileUtils, :rm, [@database_root]) do ++ ActiveRecord::Tasks::DatabaseTasks.drop @configuration, @root + end + end + + def test_when_db_dropped_successfully_outputs_info_to_stdout + FileUtils.stub(:rm, nil) do +- ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" ++ ActiveRecord::Tasks::DatabaseTasks.drop @configuration, @root + + assert_equal "Dropped database '#{@database}'\n", $stdout.string + end diff --git a/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method.patch b/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method.patch new file mode 100644 index 0000000..ac02f64 --- /dev/null +++ b/rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method.patch @@ -0,0 +1,26 @@ +From e708599c85226e9ad107ebdad09a9e31f1b5388a Mon Sep 17 00:00:00 2001 +From: Nicolas Iragorri Dominguez + +Date: Tue, 27 Dec 2022 01:24:19 +0100 +Subject: [PATCH] [issue-46741] remove `require pathname` from `drop` method + +--- + .../tasks/sqlite_database_tasks.rb | 6 +-- + +diff --git a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb +index d920d874ef308..fdfa299fa0e8c 100644 +--- a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb ++++ b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb +@@ -22,10 +22,8 @@ + end + + def drop +- require "pathname" +- path = Pathname.new(db_config.database) +- file = path.absolute? ? path.to_s : File.join(root, path) +- ++ db_path = db_config.database ++ file = File.absolute_path?(db_path) ? db_path : File.join(root, db_path) + FileUtils.rm(file) + rescue Errno::ENOENT => error + raise NoDatabaseError.new(error.message) diff --git a/rubygem-activerecord.spec b/rubygem-activerecord.spec index 975d154..a8116af 100644 --- a/rubygem-activerecord.spec +++ b/rubygem-activerecord.spec @@ -2,7 +2,7 @@ Name: rubygem-%{gem_name} Epoch: 1 Version: 7.0.4 -Release: 2 +Release: 3 Summary: Object-relational mapper framework (part of Rails) License: MIT URL: http://rubyonrails.org @@ -26,6 +26,9 @@ Patch1: rubygem-activerecord-7.0.2.3-Remove-the-multi-call-form-of- Patch2: rubygem-activerecord-7.0.2.3-Fix-tests-for-minitest-5.16.patch Patch3: CVE-2022-44566.patch Patch4: CVE-2023-22794.patch +Patch5: rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method.patch +Patch6: rubygem-activerecord-7.0.4-remove-require-pathname-from-drop-method-tests.patch + Suggests: %{_bindir}/sqlite3 BuildRequires: rubygems-devel rubygem(bcrypt) rubygem(activesupport) = %{version} BuildRequires: rubygem(activemodel) = %{version} rubygem(builder) rubygem(sqlite3) @@ -49,12 +52,14 @@ Documentation for %{name}. %setup -q -n %{gem_name}-%{version} -b1 -b2 %patch0 -p2 +%patch5 -p2 pushd %{_builddir} %patch1 -p2 %patch2 -p2 %patch3 -p1 %patch4 -p1 +%patch6 -p2 popd %build gem build ../%{gem_name}-%{version}.gemspec @@ -107,6 +112,9 @@ popd %{gem_instdir}/examples %changelog +* Mon Aug 14 2023 liyanan - 1:7.0.4-3 +- fix build error + * Wed Feb 22 2023 wushaozheng - 1:7.0.4-2 - fix CVE-2022-44566 CVE-2023-22794