From 4db7397d2a46e745da298a4abd5d6f9e3002e2d2 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 27 Dec 2021 03:20:31 +0000 Subject: [PATCH] Use File.exist? instead of deprecated File.exists? (#36358). git-svn-id: http://svn.redmine.org/redmine/trunk@21327 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/import.rb | 2 +- config/application.rb | 2 +- config/boot.rb | 2 +- config/routes.rb | 2 +- lib/redmine/scm/adapters/abstract_adapter.rb | 2 +- lib/redmine/thumbnail.rb | 4 ++-- lib/redmine/utils.rb | 2 +- lib/tasks/testing.rake | 6 +++--- test/extra/redmine_pm/repository_git_test_pm.rb | 2 +- test/extra/redmine_pm/repository_subversion_test_pm.rb | 2 +- test/functional/issues_controller_test.rb | 8 ++++---- test/unit/attachment_test.rb | 8 ++++---- test/unit/issue_import_test.rb | 4 ++-- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/models/import.rb b/app/models/import.rb index a9c40270a..5665d7316 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -111,7 +111,7 @@ class Import < ActiveRecord::Base # Returns true if the file to import exists def file_exists? - filepath.present? && File.exists?(filepath) + filepath.present? && File.exist?(filepath) end # Returns the headers as an array that diff --git a/config/application.rb b/config/application.rb index e74fcbf67..902007d03 100644 --- a/config/application.rb +++ b/config/application.rb @@ -83,7 +83,7 @@ module RedmineApp :same_site => :lax ) - if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb')) + if File.exist?(File.join(File.dirname(__FILE__), 'additional_environment.rb')) instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb')) end end diff --git a/config/boot.rb b/config/boot.rb index 4bb97ac51..7479b5aff 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,4 +3,4 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/routes.rb b/config/routes.rb index efb6db8e1..b608d5b7f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -396,7 +396,7 @@ Rails.application.routes.draw do Dir.glob File.expand_path("#{Redmine::Plugin.directory}/*") do |plugin_dir| file = File.join(plugin_dir, "config/routes.rb") - if File.exists?(file) + if File.exist?(file) begin instance_eval File.read(file) rescue SyntaxError, StandardError => e diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index d0c3293a6..4c12f4a13 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -216,7 +216,7 @@ module Redmine writable = false path = Redmine::Configuration['scm_stderr_log_file'].presence path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s - if File.exists?(path) + if File.exist?(path) if File.file?(path) && File.writable?(path) writable = true else diff --git a/lib/redmine/thumbnail.rb b/lib/redmine/thumbnail.rb index bb5c0ac06..c1da6aa41 100644 --- a/lib/redmine/thumbnail.rb +++ b/lib/redmine/thumbnail.rb @@ -36,14 +36,14 @@ module Redmine return nil unless convert_available? return nil if is_pdf && !gs_available? - unless File.exists?(target) + unless File.exist?(target) # Make sure we only invoke Imagemagick if the file type is allowed mime_type = File.open(source) {|f| Marcel::MimeType.for(f)} return nil if !ALLOWED_TYPES.include? mime_type return nil if is_pdf && mime_type != "application/pdf" directory = File.dirname(target) - unless File.exists?(directory) + unless File.exist?(directory) FileUtils.mkdir_p directory end size_option = "#{size}x#{size}>" diff --git a/lib/redmine/utils.rb b/lib/redmine/utils.rb index 2a8a04443..386919a25 100644 --- a/lib/redmine/utils.rb +++ b/lib/redmine/utils.rb @@ -51,7 +51,7 @@ module Redmine def save_upload(upload, path) directory = File.dirname(path) - unless File.exists?(directory) + unless File.exist?(directory) FileUtils.mkdir_p directory end File.open(path, "wb") do |f| diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index 6a44c3eb7..3088a4c2d 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -31,7 +31,7 @@ namespace :test do desc "Creates a test subversion repository" task :subversion => :create_dir do repo_path = "tmp/test/subversion_repository" - unless File.exists?(repo_path) + unless File.exist?(repo_path) system "svnadmin create #{repo_path}" system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}" end @@ -40,7 +40,7 @@ namespace :test do desc "Creates a test mercurial repository" task :mercurial => :create_dir do repo_path = "tmp/test/mercurial_repository" - unless File.exists?(repo_path) + unless File.exist?(repo_path) bundle_path = "test/fixtures/repositories/mercurial_repository.hg" system "hg init #{repo_path}" system "hg -R #{repo_path} pull #{bundle_path}" @@ -48,7 +48,7 @@ namespace :test do end def extract_tar_gz(prefix) - unless File.exists?("tmp/test/#{prefix}_repository") + unless File.exist?("tmp/test/#{prefix}_repository") # system "gunzip < test/fixtures/repositories/#{prefix}_repository.tar.gz | tar -xv -C tmp/test" system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{prefix}_repository.tar.gz" end diff --git a/test/extra/redmine_pm/repository_git_test_pm.rb b/test/extra/redmine_pm/repository_git_test_pm.rb index fac1017b6..1cb8ec853 100644 --- a/test/extra/redmine_pm/repository_git_test_pm.rb +++ b/test/extra/redmine_pm/repository_git_test_pm.rb @@ -74,7 +74,7 @@ class RedminePmTest::RepositoryGitTest < RedminePmTest::TestCase Dir.mktmpdir do |dir| assert_success "clone", git_url, dir Dir.chdir(dir) do - assert File.exists?(File.join(dir, "#{filename}")) + assert File.exist?(File.join(dir, "#{filename}")) end end end diff --git a/test/extra/redmine_pm/repository_subversion_test_pm.rb b/test/extra/redmine_pm/repository_subversion_test_pm.rb index 9934b3e90..ce0d628e6 100644 --- a/test/extra/redmine_pm/repository_subversion_test_pm.rb +++ b/test/extra/redmine_pm/repository_subversion_test_pm.rb @@ -305,7 +305,7 @@ class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase assert_success "update" # checks that the working copy was updated - assert File.exists?(File.join(dir, "#{filename}_copy")) + assert File.exist?(File.join(dir, "#{filename}_copy")) assert File.directory?(File.join(dir, "#{filename}_dir")) end end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 434775e59..52b63f1e0 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -4716,7 +4716,7 @@ class IssuesControllerTest < Redmine::ControllerTest assert_equal 'text/plain', attachment.content_type assert_equal 'test file', attachment.description assert_equal 59, attachment.filesize - assert File.exists?(attachment.diskfile) + assert File.exist?(attachment.diskfile) assert_equal 59, File.size(attachment.diskfile) end @@ -4780,7 +4780,7 @@ class IssuesControllerTest < Redmine::ControllerTest attachment = Attachment.order('id DESC').first assert_equal 'testfile.txt', attachment.filename - assert File.exists?(attachment.diskfile) + assert File.exist?(attachment.diskfile) assert_nil attachment.container assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token @@ -6289,7 +6289,7 @@ class IssuesControllerTest < Redmine::ControllerTest assert_equal 'text/plain', attachment.content_type assert_equal 'test file', attachment.description assert_equal 59, attachment.filesize - assert File.exists?(attachment.diskfile) + assert File.exist?(attachment.diskfile) assert_equal 59, File.size(attachment.diskfile) mail = ActionMailer::Base.deliveries.last @@ -6323,7 +6323,7 @@ class IssuesControllerTest < Redmine::ControllerTest attachment = Attachment.order('id DESC').first assert_equal 'testfile.txt', attachment.filename - assert File.exists?(attachment.diskfile) + assert File.exist?(attachment.diskfile) assert_nil attachment.container assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index 954c44269..e0b53e07b 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -208,11 +208,11 @@ class AttachmentTest < ActiveSupport::TestCase copy = a.copy copy.save! - assert File.exists?(diskfile) + assert File.exist?(diskfile) a.destroy - assert File.exists?(diskfile) + assert File.exist?(diskfile) copy.destroy - assert !File.exists?(diskfile) + assert !File.exist?(diskfile) end def test_create_should_auto_assign_content_type @@ -387,7 +387,7 @@ class AttachmentTest < ActiveSupport::TestCase assert_equal 59, attachment.filesize assert_equal 'test', attachment.description assert_equal 'text/plain', attachment.content_type - assert File.exists?(attachment.diskfile) + assert File.exist?(attachment.diskfile) assert_equal 59, File.size(attachment.diskfile) end diff --git a/test/unit/issue_import_test.rb b/test/unit/issue_import_test.rb index 1a7413890..cc16a27e5 100644 --- a/test/unit/issue_import_test.rb +++ b/test/unit/issue_import_test.rb @@ -366,10 +366,10 @@ class IssueImportTest < ActiveSupport::TestCase def test_run_should_remove_the_file import = generate_import_with_mapping file_path = import.filepath - assert File.exists?(file_path) + assert File.exist?(file_path) import.run - assert !File.exists?(file_path) + assert !File.exist?(file_path) end def test_run_should_consider_project_shared_versions -- 2.39.5