From c5fd8c42dbf82dde6734353acb3578e90ecdcb58 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 5 Jan 2022 12:45:08 -0500 Subject: [PATCH] DEV: Fix methods removed in Ruby 3.2 (#15459) * File.exists? is deprecated and removed in Ruby 3.2 in favor of File.exist? * Dir.exists? is deprecated and removed in Ruby 3.2 in favor of Dir.exist? --- app/controllers/user_avatars_controller.rb | 2 +- app/jobs/regular/export_csv_file.rb | 2 +- app/jobs/regular/export_user_archive.rb | 2 +- app/models/global_setting.rb | 2 +- app/services/handle_chunk_upload.rb | 4 ++-- bin/unicorn | 2 +- config/boot.rb | 2 +- config/initializers/100-watch_for_restart.rb | 4 ++-- config/unicorn.conf.rb | 2 +- lib/autospec/formatter.rb | 4 ++-- lib/autospec/manager.rb | 2 +- lib/autospec/qunit_runner.rb | 2 +- lib/autospec/reload_css.rb | 2 +- lib/backup_restore/backup_file_handler.rb | 2 +- lib/backup_restore/local_backup_store.rb | 6 +++--- lib/backup_restore/meta_data_handler.rb | 2 +- lib/demon/base.rb | 2 +- lib/discourse_dev/config.rb | 2 +- lib/faker/discourse_markdown.rb | 2 +- lib/file_store/base_store.rb | 2 +- lib/file_store/local_store.rb | 10 +++++----- lib/i18n/locale_file_checker.rb | 2 +- lib/letter_avatar.rb | 4 ++-- lib/plugin/instance.rb | 8 ++++---- lib/plugin_gem.rb | 4 ++-- lib/s3_inventory.rb | 8 ++++---- lib/stylesheet/manager.rb | 8 ++++---- lib/stylesheet/manager/builder.rb | 2 +- lib/tasks/assets.rake | 4 ++-- lib/tasks/emoji.rake | 8 ++++---- lib/tasks/javascript.rake | 4 ++-- lib/tasks/release_note.rake | 2 +- lib/tasks/s3.rake | 2 +- lib/tasks/site.rake | 4 ++-- lib/tasks/smoke_test.rake | 2 +- lib/tasks/uploads.rake | 12 ++++++------ lib/temporary_db.rb | 2 +- script/bench.rb | 2 +- script/bulk_import/discourse_merger.rb | 2 +- script/bulk_import/vanilla.rb | 14 +++++++------- script/bulk_import/vbulletin.rb | 6 +++--- script/bulk_import/vbulletin5.rb | 2 +- script/import_scripts/answerhub.rb | 6 +++--- script/import_scripts/base/generic_database.rb | 2 +- script/import_scripts/bbpress.rb | 2 +- script/import_scripts/discuz_x.rb | 2 +- script/import_scripts/drupal.rb | 2 +- script/import_scripts/drupal_json.rb | 2 +- script/import_scripts/friendsmegplus.rb | 2 +- script/import_scripts/getsatisfaction.rb | 2 +- script/import_scripts/google_groups.rb | 2 +- script/import_scripts/higher_logic.rb | 2 +- script/import_scripts/ipboard.rb | 2 +- script/import_scripts/ipboard3.rb | 4 ++-- script/import_scripts/lithium.rb | 6 +++--- script/import_scripts/mbox.rb | 2 +- script/import_scripts/modx.rb | 2 +- script/import_scripts/ning.rb | 10 +++++----- script/import_scripts/nodebb/nodebb.rb | 6 +++--- script/import_scripts/phpbb3.rb | 2 +- script/import_scripts/smf1.rb | 2 +- script/import_scripts/smf2.rb | 2 +- script/import_scripts/vanilla_mysql.rb | 14 +++++++------- script/import_scripts/vbulletin.rb | 2 +- script/import_scripts/vbulletin5.rb | 4 ++-- .../common_passwords/common_passwords_spec.rb | 2 +- spec/components/oneboxer_spec.rb | 2 +- spec/components/plugin/instance_spec.rb | 4 ++-- spec/lib/backup_restore/local_backup_store_spec.rb | 6 +++--- .../shared_examples_for_backup_store.rb | 2 +- spec/lib/upload_recovery_spec.rb | 2 +- spec/models/optimized_image_spec.rb | 8 ++++---- spec/rails_helper.rb | 2 +- spec/requests/admin/backups_controller_spec.rb | 6 +++--- spec/requests/api/backups_spec.rb | 2 +- 75 files changed, 140 insertions(+), 140 deletions(-) diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index d65baac29cc1f..2d339e9f54558 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -124,7 +124,7 @@ def show_in_site(hostname) elsif upload && optimized = get_optimized_image(upload, size) if optimized.local? optimized_path = Discourse.store.path_for(optimized) - image = optimized_path if File.exists?(optimized_path) + image = optimized_path if File.exist?(optimized_path) else return proxy_avatar(Discourse.store.cdn_url(optimized.url), upload.created_at) end diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb index 262e8719207fb..44305b44720a8 100644 --- a/app/jobs/regular/export_csv_file.rb +++ b/app/jobs/regular/export_csv_file.rb @@ -56,7 +56,7 @@ def execute(args) dirname = "#{UserExport.base_directory}/#{filename}" # ensure directory exists - FileUtils.mkdir_p(dirname) unless Dir.exists?(dirname) + FileUtils.mkdir_p(dirname) unless Dir.exist?(dirname) # Generate a compressed CSV file begin diff --git a/app/jobs/regular/export_user_archive.rb b/app/jobs/regular/export_user_archive.rb index 4ff3f1fcb812a..ba2442df77456 100644 --- a/app/jobs/regular/export_user_archive.rb +++ b/app/jobs/regular/export_user_archive.rb @@ -70,7 +70,7 @@ def execute(args) dirname = "#{UserExport.base_directory}/#{filename}" # ensure directory exists - FileUtils.mkdir_p(dirname) unless Dir.exists?(dirname) + FileUtils.mkdir_p(dirname) unless Dir.exist?(dirname) # Generate a compressed CSV file zip_filename = nil diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index c83db37cfae64..c39ceaefd9234 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -267,7 +267,7 @@ def resolve(current, default) class FileProvider < BaseProvider attr_reader :data def self.from(file) - if File.exists?(file) + if File.exist?(file) parse(file) end end diff --git a/app/services/handle_chunk_upload.rb b/app/services/handle_chunk_upload.rb index 2bd365b64323e..d966f659aa163 100644 --- a/app/services/handle_chunk_upload.rb +++ b/app/services/handle_chunk_upload.rb @@ -21,7 +21,7 @@ def self.merge_chunks(chunk, params) def check_chunk # check whether the chunk has already been uploaded - has_chunk_been_uploaded = File.exists?(@chunk) && File.size(@chunk) == @params[:current_chunk_size] + has_chunk_been_uploaded = File.exist?(@chunk) && File.size(@chunk) == @params[:current_chunk_size] # 200 = exists, 404 = not uploaded yet status = has_chunk_been_uploaded ? 200 : 404 end @@ -30,7 +30,7 @@ def upload_chunk # path to chunk file dir = File.dirname(@chunk) # ensure directory exists - FileUtils.mkdir_p(dir) unless Dir.exists?(dir) + FileUtils.mkdir_p(dir) unless Dir.exist?(dir) # save chunk to the directory File.open(@chunk, "wb") { |f| f.write(@params[:file].tempfile.read) } end diff --git a/bin/unicorn b/bin/unicorn index c52d2f8394df0..9735e3eec0bad 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -26,7 +26,7 @@ def ensure_cache_clean! super_sha = Digest::SHA1.hexdigest(core_git_sha + plugins_combined_git_sha) hash_file = "#{RAILS_ROOT}/tmp/plugin-hash" - old_hash = File.exists?(hash_file) ? File.read(hash_file) : nil + old_hash = File.exist?(hash_file) ? File.read(hash_file) : nil if old_hash && old_hash != super_sha puts "WARNING: It looks like your discourse plugins or core version have recently changed." diff --git a/config/boot.rb b/config/boot.rb index f3b61fd24cc8f..6866506f24bec 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -10,7 +10,7 @@ # 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']) if (ENV['DISABLE_BOOTSNAP'] != '1') begin diff --git a/config/initializers/100-watch_for_restart.rb b/config/initializers/100-watch_for_restart.rb index 922380cf675a8..0998cf01b1975 100644 --- a/config/initializers/100-watch_for_restart.rb +++ b/config/initializers/100-watch_for_restart.rb @@ -14,7 +14,7 @@ Thread.new do file = "#{Rails.root}/tmp/restart" - old_time = File.ctime(file).to_i if File.exists? file + old_time = File.ctime(file).to_i if File.exist? file wait_seconds = 4 if Rails.env.development? && $PROGRAM_NAME =~ /puma/ @@ -25,7 +25,7 @@ begin listener = Listen.to("#{Rails.root}/tmp", only: /restart/) do - time = File.ctime(file).to_i if File.exists? file + time = File.ctime(file).to_i if File.exist? file if old_time != time Rails.logger.info "attempting to reload #{$$} #{$PROGRAM_NAME} in #{wait_seconds} seconds" diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rb index b00fca1883fc0..50b0a6229743f 100644 --- a/config/unicorn.conf.rb +++ b/config/unicorn.conf.rb @@ -71,7 +71,7 @@ if supervisor > 0 Thread.new do while true - unless File.exists?("/proc/#{supervisor}") + unless File.exist?("/proc/#{supervisor}") puts "Kill self supervisor is gone" Process.kill "TERM", Process.pid end diff --git a/lib/autospec/formatter.rb b/lib/autospec/formatter.rb index 8b5b3ac416214..a6b26aff7fff7 100644 --- a/lib/autospec/formatter.rb +++ b/lib/autospec/formatter.rb @@ -13,8 +13,8 @@ class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter def initialize(output) super - FileUtils.mkdir_p("tmp") unless Dir.exists?("tmp") - File.delete(RSPEC_RESULT) if File.exists?(RSPEC_RESULT) + FileUtils.mkdir_p("tmp") unless Dir.exist?("tmp") + File.delete(RSPEC_RESULT) if File.exist?(RSPEC_RESULT) @fail_file = File.open(RSPEC_RESULT, "w") end diff --git a/lib/autospec/manager.rb b/lib/autospec/manager.rb index bd8e49803b3b2..175f743aa90b8 100644 --- a/lib/autospec/manager.rb +++ b/lib/autospec/manager.rb @@ -295,7 +295,7 @@ def process_change(files) if spec == file && line with_line = spec + ":" << line.to_s end - if File.exists?(spec) || Dir.exists?(spec) + if File.exist?(spec) || Dir.exist?(spec) if with_line != spec specs << [file, spec, runner] end diff --git a/lib/autospec/qunit_runner.rb b/lib/autospec/qunit_runner.rb index ec76a240cd79e..a50ed7593a3a4 100644 --- a/lib/autospec/qunit_runner.rb +++ b/lib/autospec/qunit_runner.rb @@ -152,7 +152,7 @@ def kill_process(pid) def try_to_find_module_name(file) file, _ = file.split(/:\d+$/) - return unless File.exists?(file) + return unless File.exist?(file) File.open(file, "r").each_line do |line| if m = /module\(['"]([^'"]+)/i.match(line) return m[1] diff --git a/lib/autospec/reload_css.rb b/lib/autospec/reload_css.rb index 54753e22ff52c..8f24cdec98437 100644 --- a/lib/autospec/reload_css.rb +++ b/lib/autospec/reload_css.rb @@ -40,7 +40,7 @@ def self.run_on_change(paths) paths.map! do |p| hash = nil fullpath = "#{Rails.root}/#{p}" - hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exists?(fullpath) + hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exist?(fullpath) p = p.sub(/\.sass\.erb/, "") p = p.sub(/\.sass/, "") p = p.sub(/\.scss/, "") diff --git a/lib/backup_restore/backup_file_handler.rb b/lib/backup_restore/backup_file_handler.rb index d9369789fb8b3..483d6f6473a63 100644 --- a/lib/backup_restore/backup_file_handler.rb +++ b/lib/backup_restore/backup_file_handler.rb @@ -86,7 +86,7 @@ def extract_db_dump if @is_archive # for compatibility with backups from Discourse v1.5 and below old_dump_path = File.join(@tmp_directory, OLD_DUMP_FILENAME) - File.exists?(old_dump_path) ? old_dump_path : File.join(@tmp_directory, BackupRestore::DUMP_FILE) + File.exist?(old_dump_path) ? old_dump_path : File.join(@tmp_directory, BackupRestore::DUMP_FILE) else File.join(@tmp_directory, @filename) end diff --git a/lib/backup_restore/local_backup_store.rb b/lib/backup_restore/local_backup_store.rb index 1b1cb977f5cfd..fd7f16b9f63b6 100644 --- a/lib/backup_restore/local_backup_store.rb +++ b/lib/backup_restore/local_backup_store.rb @@ -7,7 +7,7 @@ def self.base_directory(db: nil, root_directory: nil) root_directory ||= File.join(Rails.root, "public", "backups") base_directory = File.join(root_directory, current_db) - FileUtils.mkdir_p(base_directory) unless Dir.exists?(base_directory) + FileUtils.mkdir_p(base_directory) unless Dir.exist?(base_directory) base_directory end @@ -25,13 +25,13 @@ def remote? def file(filename, include_download_source: false) path = path_from_filename(filename) - create_file_from_path(path, include_download_source) if File.exists?(path) + create_file_from_path(path, include_download_source) if File.exist?(path) end def delete_file(filename) path = path_from_filename(filename) - if File.exists?(path) + if File.exist?(path) File.delete(path) reset_cache end diff --git a/lib/backup_restore/meta_data_handler.rb b/lib/backup_restore/meta_data_handler.rb index 002bbd0d2851c..02bc0e98bf0bf 100644 --- a/lib/backup_restore/meta_data_handler.rb +++ b/lib/backup_restore/meta_data_handler.rb @@ -42,7 +42,7 @@ def validate def extract_metadata metadata_path = File.join(@tmp_directory, METADATA_FILE) if @tmp_directory.present? - if metadata_path.present? && File.exists?(metadata_path) + if metadata_path.present? && File.exist?(metadata_path) metadata = load_metadata_file(metadata_path) elsif @filename =~ /-#{BackupRestore::VERSION_PREFIX}(\d{14})/ metadata = { version: Regexp.last_match[1].to_i } diff --git a/lib/demon/base.rb b/lib/demon/base.rb index 2d6d46e2955bc..397fb5d0b08fd 100644 --- a/lib/demon/base.rb +++ b/lib/demon/base.rb @@ -151,7 +151,7 @@ def run end def already_running? - if File.exists? pid_file + if File.exist? pid_file pid = File.read(pid_file).to_i if Demon::Base.alive?(pid) return pid diff --git a/lib/discourse_dev/config.rb b/lib/discourse_dev/config.rb index 4a2142b43c6e1..eb4a1d160bd8c 100644 --- a/lib/discourse_dev/config.rb +++ b/lib/discourse_dev/config.rb @@ -12,7 +12,7 @@ def initialize @file_path = File.join(Rails.root, "config", "dev.yml") default_config = YAML.load_file(default_file_path) - if File.exists?(file_path) + if File.exist?(file_path) user_config = YAML.load_file(file_path) else puts "I did no detect a custom `config/dev.yml` file, creating one for you where you can amend defaults." diff --git a/lib/faker/discourse_markdown.rb b/lib/faker/discourse_markdown.rb index b858e996c6141..8f5266a1914c4 100644 --- a/lib/faker/discourse_markdown.rb +++ b/lib/faker/discourse_markdown.rb @@ -72,7 +72,7 @@ def image_cache_dir def load_image(image) cache_path = ::File.join(image_cache_dir, image[:filename]) - if !::File.exists?(cache_path) + if !::File.exist?(cache_path) FileUtils.mkdir_p(image_cache_dir) temp_file = ::FileHelper.download( image[:url], diff --git a/lib/file_store/base_store.rb b/lib/file_store/base_store.rb index 5d21449bcdbac..eec747ba08056 100644 --- a/lib/file_store/base_store.rb +++ b/lib/file_store/base_store.rb @@ -173,7 +173,7 @@ def get_cache_path_for(filename) def get_from_cache(filename) path = get_cache_path_for(filename) - File.open(path) if File.exists?(path) + File.open(path) if File.exist?(path) end def cache_file(file, filename) diff --git a/lib/file_store/local_store.rb b/lib/file_store/local_store.rb index e71e3a6ba7643..9e704efee984e 100644 --- a/lib/file_store/local_store.rb +++ b/lib/file_store/local_store.rb @@ -14,11 +14,11 @@ def store_file(file, path) def remove_file(url, _) return unless is_relative?(url) source = "#{public_dir}#{url}" - return unless File.exists?(source) + return unless File.exist?(source) destination = "#{public_dir}#{url.sub("/uploads/", "/uploads/tombstone/")}" dir = Pathname.new(destination).dirname - FileUtils.mkdir_p(dir) unless Dir.exists?(dir) - FileUtils.remove(destination) if File.exists?(destination) + FileUtils.mkdir_p(dir) unless Dir.exist?(dir) + FileUtils.remove(destination) if File.exist?(destination) FileUtils.move(source, destination, force: true) FileUtils.touch(destination) end @@ -62,7 +62,7 @@ def path_for(upload) end def purge_tombstone(grace_period) - if Dir.exists?(Discourse.store.tombstone_dir) + if Dir.exist?(Discourse.store.tombstone_dir) Discourse::Utils.execute_command( 'find', tombstone_dir, '-mtime', "+#{grace_period}", '-type', 'f', '-delete' ) @@ -75,7 +75,7 @@ def get_path_for(type, upload_id, sha, extension) def copy_file(file, path) dir = Pathname.new(path).dirname - FileUtils.mkdir_p(dir) unless Dir.exists?(dir) + FileUtils.mkdir_p(dir) unless Dir.exist?(dir) # move the file to the right location # not using mv, cause permissions are no good on move File.open(path, "wb") { |f| f.write(file.read) } diff --git a/lib/i18n/locale_file_checker.rb b/lib/i18n/locale_file_checker.rb index 757e9b969a239..4d0088ab8c681 100644 --- a/lib/i18n/locale_file_checker.rb +++ b/lib/i18n/locale_file_checker.rb @@ -49,7 +49,7 @@ def locale_files def reference_file(path) path = path.gsub(/\.\w{2,}\.yml$/, ".#{REFERENCE_LOCALE}.yml") - path if File.exists?(path) + path if File.exist?(path) end def traverse_hash(hash, parent_keys, &block) diff --git a/lib/letter_avatar.rb b/lib/letter_avatar.rb index cdd054626a26b..1a8524f338a3f 100644 --- a/lib/letter_avatar.rb +++ b/lib/letter_avatar.rb @@ -42,10 +42,10 @@ def generate(username, size, opts = nil) size = FULLSIZE if size > FULLSIZE filename = cached_path(identity, size) - return filename if cache && File.exists?(filename) + return filename if cache && File.exist?(filename) fullsize = fullsize_path(identity) - generate_fullsize(identity) if !cache || !File.exists?(fullsize) + generate_fullsize(identity) if !cache || !File.exist?(fullsize) # Optimizing here is dubious, it can save up to 2x for large images (eg 359px) # BUT... we are talking 2400 bytes down to 1200 bytes, both fit in one packet diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 1e9526aceda4e..50f4ae04e1083 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -424,7 +424,7 @@ def add_directory_column(column_name, query:, icon: nil) end def delete_extra_automatic_assets(good_paths) - return unless Dir.exists? auto_generated_path + return unless Dir.exist? auto_generated_path filenames = good_paths.map { |f| File.basename(f) } # nuke old files @@ -701,7 +701,7 @@ def activate! end public_data = File.dirname(path) + "/public" - if Dir.exists?(public_data) + if Dir.exist?(public_data) target = Rails.root.to_s + "/public/plugins/" Discourse::Utils.execute_command('mkdir', '-p', target) @@ -839,7 +839,7 @@ def css_asset_exists?(target = nil) end def js_asset_exists? - File.exists?(js_file_path) + File.exist?(js_file_path) end # Receives an array with two elements: @@ -1085,7 +1085,7 @@ def validate_directory_column_name(column_name) end def write_asset(path, contents) - unless File.exists?(path) + unless File.exist?(path) ensure_directory(path) File.open(path, "w") { |f| f.write(contents) } end diff --git a/lib/plugin_gem.rb b/lib/plugin_gem.rb index 855d1aca2c13b..c870680dbd798 100644 --- a/lib/plugin_gem.rb +++ b/lib/plugin_gem.rb @@ -12,14 +12,14 @@ def self.load(path, name, version, opts = nil) spec_file += "-#{opts[:platform]}" if opts[:platform] spec_file += ".gemspec" - unless File.exists? spec_file + unless File.exist? spec_file command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install" command += " --source #{opts[:source]}" if opts[:source] puts command puts `#{command}` end - if File.exists? spec_file + if File.exist? spec_file Gem.path << gems_path Gem::Specification.load(spec_file).activate diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb index 80239130c3b09..c62ee62c81b2a 100644 --- a/lib/s3_inventory.rb +++ b/lib/s3_inventory.rb @@ -140,7 +140,7 @@ def for_each_inventory_row end def download_inventory_file_to_tmp_directory(file) - return if File.exists?(file[:filename]) + return if File.exist?(file[:filename]) log "Downloading inventory file '#{file[:key]}' to tmp directory..." failure_message = "Failed to inventory file '#{file[:key]}' to tmp directory." @@ -219,8 +219,8 @@ def prepare_for_all_sites def cleanup! return if @preloaded_inventory_file files.each do |file| - File.delete(file[:filename]) if File.exists?(file[:filename]) - File.delete(file[:filename][0...-3]) if File.exists?(file[:filename][0...-3]) + File.delete(file[:filename]) if File.exist?(file[:filename]) + File.delete(file[:filename][0...-3]) if File.exist?(file[:filename][0...-3]) end end @@ -253,7 +253,7 @@ def files def download_and_decompress_files files.each do |file| - next if File.exists?(file[:filename][0...-3]) + next if File.exist?(file[:filename][0...-3]) download_inventory_file_to_tmp_directory(file) decompress_inventory_file(file) diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb index a9b9c631b1f40..43b5bdf1ed22f 100644 --- a/lib/stylesheet/manager.rb +++ b/lib/stylesheet/manager.rb @@ -107,7 +107,7 @@ def self.precompile_theme_css def self.last_file_updated if Rails.env.production? - @last_file_updated ||= if File.exists?(MANIFEST_FULL_PATH) + @last_file_updated ||= if File.exist?(MANIFEST_FULL_PATH) File.readlines(MANIFEST_FULL_PATH, 'r')[0] else mtime = max_file_mtime @@ -224,7 +224,7 @@ def stylesheet_details(target = :desktop, media = 'all') builder = Builder.new(target: target, theme: theme, manager: self) next if builder.theme&.component && !scss_checker.has_scss(theme_id) - builder.compile unless File.exists?(builder.stylesheet_fullpath) + builder.compile unless File.exist?(builder.stylesheet_fullpath) href = builder.stylesheet_path(current_hostname) data[:new_href] = href @@ -242,7 +242,7 @@ def stylesheet_details(target = :desktop, media = 'all') end else builder = Builder.new(target: target, manager: self) - builder.compile unless File.exists?(builder.stylesheet_fullpath) + builder.compile unless File.exist?(builder.stylesheet_fullpath) href = builder.stylesheet_path(current_hostname) data = { target: target, new_href: href } @@ -285,7 +285,7 @@ def color_scheme_stylesheet_details(color_scheme_id = nil, media) manager: self ) - builder.compile unless File.exists?(builder.stylesheet_fullpath) + builder.compile unless File.exist?(builder.stylesheet_fullpath) href = builder.stylesheet_path(current_hostname) stylesheet[:new_href] = href diff --git a/lib/stylesheet/manager/builder.rb b/lib/stylesheet/manager/builder.rb index 0b89cd8dc6c30..b88730f16537c 100644 --- a/lib/stylesheet/manager/builder.rb +++ b/lib/stylesheet/manager/builder.rb @@ -12,7 +12,7 @@ def initialize(target: :desktop, theme: nil, color_scheme: nil, manager:) def compile(opts = {}) if !opts[:force] - if File.exists?(stylesheet_fullpath) + if File.exist?(stylesheet_fullpath) unless StylesheetCache.where(target: qualified_target, digest: digest).exists? begin source_map = begin diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 39bf7a3bf71b2..c8025a92cea07 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -260,7 +260,7 @@ def copy_ember_cli_assets dest_sub = "#{dest}/#{Regexp.last_match[1]}" end - FileUtils.mkdir_p(dest_sub) unless Dir.exists?(dest_sub) + FileUtils.mkdir_p(dest_sub) unless Dir.exist?(dest_sub) log_file = File.basename(rel_file).sub("-#{digest}", "") # It's simpler to serve the file as `application.js` @@ -362,7 +362,7 @@ task 'assets:precompile' => 'assets:precompile:before' do _file = (d = File.dirname(file)) == "." ? "_#{file}" : "#{d}/_#{File.basename(file)}" _path = "#{assets_path}/#{_file}" max_compress = max_compress?(info["logical_path"], locales) - if File.exists?(_path) + if File.exist?(_path) STDERR.puts "Skipping: #{file} already compressed" elsif file.include? "discourse/tests" STDERR.puts "Skipping: #{file}" diff --git a/lib/tasks/emoji.rake b/lib/tasks/emoji.rake index 07b0046aa3942..dc92250cdd547 100644 --- a/lib/tasks/emoji.rake +++ b/lib/tasks/emoji.rake @@ -511,12 +511,12 @@ class TestEmojiUpdate < MiniTest::Test end def test_groups_js_es6_creation - assert File.exists?(EMOJI_GROUPS_PATH) + assert File.exist?(EMOJI_GROUPS_PATH) assert File.size?(EMOJI_GROUPS_PATH) end def test_db_json_creation - assert File.exists?(EMOJI_DB_PATH) + assert File.exist?(EMOJI_DB_PATH) assert File.size?(EMOJI_DB_PATH) end @@ -536,12 +536,12 @@ class TestEmojiUpdate < MiniTest::Test def test_scales original_image = image_path("apple", "blonde_woman") - assert File.exists?(original_image) + assert File.exist?(original_image) assert File.size?(original_image) (2..6).each do |scale| image = image_path("apple", "blonde_woman/#{scale}") - assert File.exists?(image) + assert File.exist?(image) assert File.size?(image) end end diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake index 2c09ce9dd041f..70570efe0bdf5 100644 --- a/lib/tasks/javascript.rake +++ b/lib/tasks/javascript.rake @@ -307,7 +307,7 @@ task 'javascript:update' => 'clean_up' do path = "#{public_js}/#{package_dir_name}/#{package_version}" dest = "#{path}/#{filename}" - FileUtils.mkdir_p(path) unless File.exists?(path) + FileUtils.mkdir_p(path) unless File.exist?(path) end else dest = "#{vendor_js}/#{filename}" @@ -336,7 +336,7 @@ task 'javascript:update' => 'clean_up' do system("yarn run browserify #{vendor_js}/custom-uppy.js -o node_modules/custom-uppy-build.js") end - unless File.exists?(dest) + unless File.exist?(dest) STDERR.puts "New dependency added: #{dest}" end diff --git a/lib/tasks/release_note.rake b/lib/tasks/release_note.rake index 0b75aae522450..eb3cf8f737a5c 100644 --- a/lib/tasks/release_note.rake +++ b/lib/tasks/release_note.rake @@ -37,7 +37,7 @@ task "release_note:plugins:generate", :from, :to, :plugin_glob, :org do |t, args plugin_glob = args[:plugin_glob] || "./plugins/*" git_org = args[:org] - all_repos = Dir.glob(plugin_glob).filter { |f| File.directory?(f) && File.exists?("#{f}/.git") } + all_repos = Dir.glob(plugin_glob).filter { |f| File.directory?(f) && File.exist?("#{f}/.git") } if git_org all_repos = all_repos.filter { |dir| `git -C #{dir} remote get-url origin`.match?(/github.com[\/:]#{git_org}\//) } diff --git a/lib/tasks/s3.rake b/lib/tasks/s3.rake index 7b7258d6d474b..2c54f9f6a4974 100644 --- a/lib/tasks/s3.rake +++ b/lib/tasks/s3.rake @@ -38,7 +38,7 @@ def upload(path, remote_path, content_type, content_encoding = nil) end end - File.delete(path) if (File.exists?(path) && ENV["DELETE_ASSETS_AFTER_S3_UPLOAD"]) + File.delete(path) if (File.exist?(path) && ENV["DELETE_ASSETS_AFTER_S3_UPLOAD"]) end def use_db_s3_config diff --git a/lib/tasks/site.rake b/lib/tasks/site.rake index ba984bd403763..9a05d5fd96c73 100644 --- a/lib/tasks/site.rake +++ b/lib/tasks/site.rake @@ -97,7 +97,7 @@ task 'site:export_structure', [:zip_path] => :environment do |task, args| if args[:zip_path].blank? STDERR.puts "ERROR: rake site:export_structure[]" exit 1 - elsif File.exists?(args[:zip_path]) + elsif File.exist?(args[:zip_path]) STDERR.puts "ERROR: File '#{args[:zip_path]}' already exists" exit 2 end @@ -328,7 +328,7 @@ task 'site:import_structure', [:zip_path] => :environment do |task, args| if args[:zip_path].blank? STDERR.puts "ERROR: rake site:import_structure[]" exit 1 - elsif !File.exists?(args[:zip_path]) + elsif !File.exist?(args[:zip_path]) STDERR.puts "ERROR: File '#{args[:zip_path]}' does not exist" exit 2 end diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake index 4f48dff0c0ab9..cc686ddf22308 100644 --- a/lib/tasks/smoke_test.rake +++ b/lib/tasks/smoke_test.rake @@ -31,7 +31,7 @@ task "smoke:test" do end dir = ENV["SMOKE_TEST_SCREENSHOT_PATH"] || 'tmp/smoke-test-screenshots' - FileUtils.mkdir_p(dir) unless Dir.exists?(dir) + FileUtils.mkdir_p(dir) unless Dir.exist?(dir) wait = ENV["WAIT_FOR_URL"].to_i diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 924ee6050304e..4a043ca151755 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -19,7 +19,7 @@ def gather_uploads_for_all_sites end def file_exists?(path) - File.exists?(path) && File.size(path) > 0 + File.exist?(path) && File.size(path) > 0 rescue false end @@ -188,7 +188,7 @@ def clean_up_uploads Upload.find_each do |upload| path = File.join(public_directory, upload.url) - if !File.exists?(path) + if !File.exist?(path) upload.destroy! putc "#" else @@ -200,7 +200,7 @@ def clean_up_uploads OptimizedImage.find_each do |optimized_image| path = File.join(public_directory, optimized_image.url) - if !File.exists?(path) + if !File.exist?(path) optimized_image.destroy! putc "#" else @@ -326,9 +326,9 @@ def regenerate_missing_optimized thumbnail = "#{public_directory}#{optimized_image.url}" original = "#{public_directory}#{upload.url}" - if !File.exists?(thumbnail) || File.size(thumbnail) <= 0 + if !File.exist?(thumbnail) || File.size(thumbnail) <= 0 # make sure the original image exists locally - if (!File.exists?(original) || File.size(original) <= 0) && upload.origin.present? + if (!File.exist?(original) || File.size(original) <= 0) && upload.origin.present? # try to fix it by redownloading it begin downloaded = FileHelper.download( @@ -346,7 +346,7 @@ def regenerate_missing_optimized end end - if File.exists?(original) && File.size(original) > 0 + if File.exist?(original) && File.size(original) > 0 FileUtils.mkdir_p(File.dirname(thumbnail)) OptimizedImage.resize(original, thumbnail, optimized_image.width, optimized_image.height) putc "#" diff --git a/lib/temporary_db.rb b/lib/temporary_db.rb index 3b7a42e9b5e6f..1bcffa570d847 100644 --- a/lib/temporary_db.rb +++ b/lib/temporary_db.rb @@ -24,7 +24,7 @@ def pg_bin_path end if !@pg_bin_path bin_path = "/Applications/Postgres.app/Contents/Versions/latest/bin" - if File.exists?("#{bin_path}/pg_ctl") + if File.exist?("#{bin_path}/pg_ctl") @pg_bin_path = bin_path end end diff --git a/script/bench.rb b/script/bench.rb index d1ab78d791aa3..86f6c6c73cf1b 100644 --- a/script/bench.rb +++ b/script/bench.rb @@ -112,7 +112,7 @@ def prereqs abort "Apache Bench is not installed. Try: apt-get install apache2-utils or brew install ab" end -unless File.exists?("config/database.yml") +unless File.exist?("config/database.yml") puts "Copying database.yml.development.sample to database.yml" `cp config/database.yml.development-sample config/database.yml` end diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rb index da2a9c6a1146c..e1ab58c83c377 100644 --- a/script/bulk_import/discourse_merger.rb +++ b/script/bulk_import/discourse_merger.rb @@ -359,7 +359,7 @@ def copy_uploads next if row['user_id'].nil? end - row['url'] = "/uploads/default/#{rel_filename}" if File.exists?(absolute_filename) + row['url'] = "/uploads/default/#{rel_filename}" if File.exist?(absolute_filename) @raw_connection.put_copy_data(row.values) end diff --git a/script/bulk_import/vanilla.rb b/script/bulk_import/vanilla.rb index cb85b853f930f..d01eed3af037f 100644 --- a/script/bulk_import/vanilla.rb +++ b/script/bulk_import/vanilla.rb @@ -203,7 +203,7 @@ def import_user_stats end def import_avatars - if ATTACHMENTS_BASE_DIR && File.exists?(ATTACHMENTS_BASE_DIR) + if ATTACHMENTS_BASE_DIR && File.exist?(ATTACHMENTS_BASE_DIR) puts "", "importing user avatars" start = Time.now @@ -237,7 +237,7 @@ def import_avatars next end - if !File.exists?(photo_path) + if !File.exist?(photo_path) puts "Path to avatar file not found! Skipping. #{photo_path}" next end @@ -265,7 +265,7 @@ def import_avatars end def import_attachments - if ATTACHMENTS_BASE_DIR && File.exists?(ATTACHMENTS_BASE_DIR) + if ATTACHMENTS_BASE_DIR && File.exist?(ATTACHMENTS_BASE_DIR) puts "", "importing attachments" start = Time.now @@ -297,7 +297,7 @@ def import_attachments path.gsub!("s3://uploads/", "") file_path = "#{ATTACHMENTS_BASE_DIR}/#{path}" - if File.exists?(file_path) + if File.exist?(file_path) upload = create_upload(post.user.id, file_path, File.basename(file_path)) if upload && upload.errors.empty? # upload.url @@ -318,7 +318,7 @@ def import_attachments file_path = "#{ATTACHMENTS_BASE_DIR}/#{attachment_id}" - if File.exists?(file_path) + if File.exist?(file_path) upload = create_upload(post.user.id, file_path, File.basename(file_path)) if upload && upload.errors.empty? upload.url @@ -348,13 +348,13 @@ def find_photo_file(path, base_filename) base_guess = base_filename.dup full_guess = File.join(path, base_guess) # often an exact match exists - return full_guess if File.exists?(full_guess) + return full_guess if File.exist?(full_guess) # Otherwise, the file exists but with a prefix: # The p prefix seems to be the full file, so try to find that one first. ['p', 't', 'n'].each do |prefix| full_guess = File.join(path, "#{prefix}#{base_guess}") - return full_guess if File.exists?(full_guess) + return full_guess if File.exist?(full_guess) end # Didn't find it. diff --git a/script/bulk_import/vbulletin.rb b/script/bulk_import/vbulletin.rb index 8a57522002c8c..511d7a8cea2ce 100644 --- a/script/bulk_import/vbulletin.rb +++ b/script/bulk_import/vbulletin.rb @@ -531,7 +531,7 @@ def find_upload(post, attachment_id) real_filename = db_filename real_filename.prepend SecureRandom.hex if real_filename[0] == '.' - unless File.exists?(filename) + unless File.exist?(filename) puts "Attachment file #{row.inspect} doesn't exist" return nil end @@ -601,7 +601,7 @@ def import_attachments end def import_avatars - if AVATAR_DIR && File.exists?(AVATAR_DIR) + if AVATAR_DIR && File.exist?(AVATAR_DIR) puts "", "importing user avatars" RateLimiter.disable @@ -620,7 +620,7 @@ def import_avatars # raise "User not found for id #{user_id}" if user.blank? photo_real_filename = File.join(AVATAR_DIR, item) - puts "#{photo_real_filename} not found" unless File.exists?(photo_real_filename) + puts "#{photo_real_filename} not found" unless File.exist?(photo_real_filename) upload = create_upload(u.id, photo_real_filename, File.basename(photo_real_filename)) count += 1 diff --git a/script/bulk_import/vbulletin5.rb b/script/bulk_import/vbulletin5.rb index 507eb3d5d2cc0..9be967c25c463 100644 --- a/script/bulk_import/vbulletin5.rb +++ b/script/bulk_import/vbulletin5.rb @@ -616,7 +616,7 @@ def find_upload(post, opts = {}) real_filename = db_filename real_filename.prepend SecureRandom.hex if real_filename[0] == '.' - unless File.exists?(filename) + unless File.exist?(filename) filename = check_database_for_attachment(row) if filename.blank? return nil if filename.nil? end diff --git a/script/import_scripts/answerhub.rb b/script/import_scripts/answerhub.rb index 035d625c293e7..f2e05811bacc7 100644 --- a/script/import_scripts/answerhub.rb +++ b/script/import_scripts/answerhub.rb @@ -367,7 +367,7 @@ def import_avatars if user filename = "avatar-#{user_id}.png" path = File.join(AVATAR_DIR, filename) - next if !File.exists?(path) + next if !File.exist?(path) # Scrape Avatars - Avatars are saved in the db, but it might be easier to just scrape them if SCRAPE_AVATARS == 1 @@ -403,7 +403,7 @@ def process_uploads(body, user_id) filepath = File.basename(image).split('"')[0] filepath = File.join(ATTACHMENT_DIR, filepath) - if File.exists?(filepath) + if File.exist?(filepath) filename = File.basename(filepath) upload = create_upload(user_id, filepath, filename) image_html = html_for_upload(upload, filename) @@ -421,7 +421,7 @@ def process_uploads(body, user_id) filepath = File.basename(file).split('"')[0] filepath = File.join(ATTACHMENT_DIR, filepath) - if File.exists?(filepath) + if File.exist?(filepath) filename = File.basename(filepath) upload = create_upload(user_id, filepath, filename) file_html = html_for_upload(upload, filename) diff --git a/script/import_scripts/base/generic_database.rb b/script/import_scripts/base/generic_database.rb index 2b10e0c25ad1a..28bfd8ee3bf86 100644 --- a/script/import_scripts/base/generic_database.rb +++ b/script/import_scripts/base/generic_database.rb @@ -6,7 +6,7 @@ module ImportScripts class GenericDatabase def initialize(directory, batch_size:, recreate: false, numeric_keys: false) filename = "#{directory}/index.db" - File.delete(filename) if recreate && File.exists?(filename) + File.delete(filename) if recreate && File.exist?(filename) @db = SQLite3::Database.new(filename, results_as_hash: true) @batch_size = batch_size diff --git a/script/import_scripts/bbpress.rb b/script/import_scripts/bbpress.rb index 1db8c2c0d8c99..2cd0698d12325 100644 --- a/script/import_scripts/bbpress.rb +++ b/script/import_scripts/bbpress.rb @@ -316,7 +316,7 @@ def import_attachments_from_postmeta attachments.each do |a| print_status(count += 1, total_attachments, get_start_time("attachments_from_postmeta")) path = File.join(BB_PRESS_ATTACHMENTS_DIR, a["meta_value"]) - if File.exists?(path) + if File.exist?(path) if post = Post.find_by(id: post_id_from_imported_post_id(a["post_id"])) filename = File.basename(a["meta_value"]) upload = create_upload(post.user.id, path, filename) diff --git a/script/import_scripts/discuz_x.rb b/script/import_scripts/discuz_x.rb index edced0e7ab31d..1b3cb5b8cbc71 100644 --- a/script/import_scripts/discuz_x.rb +++ b/script/import_scripts/discuz_x.rb @@ -927,7 +927,7 @@ def find_upload(user, post, upload_id) end filename = File.join(DISCUZX_BASE_DIR, ATTACHMENT_DIR, row['attachment_path']) - unless File.exists?(filename) + unless File.exist?(filename) puts "Attachment file doesn't exist: #{filename}" return nil end diff --git a/script/import_scripts/drupal.rb b/script/import_scripts/drupal.rb index a10615fe3207c..23348c055bf80 100644 --- a/script/import_scripts/drupal.rb +++ b/script/import_scripts/drupal.rb @@ -428,7 +428,7 @@ def find_upload(post, attachment) real_filename = CGI.unescapeHTML(uri) file = File.join(ATTACHMENT_DIR, real_filename) - unless File.exists?(file) + unless File.exist?(file) puts "Attachment file #{attachment['filename']} doesn't exist" tmpfile = "attachments_failed.txt" diff --git a/script/import_scripts/drupal_json.rb b/script/import_scripts/drupal_json.rb index 3b72e7d61ad40..d69f21e01bd05 100644 --- a/script/import_scripts/drupal_json.rb +++ b/script/import_scripts/drupal_json.rb @@ -23,7 +23,7 @@ def execute def load_json(arg) filename = File.join(JSON_FILES_DIR, arg) - raise RuntimeError.new("File #{filename} not found!") if !File.exists?(filename) + raise RuntimeError.new("File #{filename} not found!") if !File.exist?(filename) JSON.parse(File.read(filename)).reverse end diff --git a/script/import_scripts/friendsmegplus.rb b/script/import_scripts/friendsmegplus.rb index ee22dd9cbcabe..d66eed12cc147 100644 --- a/script/import_scripts/friendsmegplus.rb +++ b/script/import_scripts/friendsmegplus.rb @@ -178,7 +178,7 @@ def execute end def load_fmgp_json(filename) - raise RuntimeError.new("File #{filename} not found") if !File.exists?(filename) + raise RuntimeError.new("File #{filename} not found") if !File.exist?(filename) JSON.parse(File.read(filename)) end diff --git a/script/import_scripts/getsatisfaction.rb b/script/import_scripts/getsatisfaction.rb index 495cc50c0ed0c..50f8613e683c6 100644 --- a/script/import_scripts/getsatisfaction.rb +++ b/script/import_scripts/getsatisfaction.rb @@ -69,7 +69,7 @@ def execute def csv_filename(table_name, use_fixed: true) if use_fixed filename = File.join(@path, "#{table_name}_fixed.csv") - return filename if File.exists?(filename) + return filename if File.exist?(filename) end File.join(@path, "#{table_name}.csv") diff --git a/script/import_scripts/google_groups.rb b/script/import_scripts/google_groups.rb index 359114e6627bc..ab7bb3038952a 100755 --- a/script/import_scripts/google_groups.rb +++ b/script/import_scripts/google_groups.rb @@ -223,7 +223,7 @@ def crawl start_time = Time.now status_filename = File.join(@path, "status.yml") - if File.exists?(status_filename) + if File.exist?(status_filename) yaml = YAML.load_file(status_filename) @finished = yaml[:finished] @scraped_topic_urls = yaml[:urls] diff --git a/script/import_scripts/higher_logic.rb b/script/import_scripts/higher_logic.rb index 1f5b1d9599e21..fe6e19641ddbc 100644 --- a/script/import_scripts/higher_logic.rb +++ b/script/import_scripts/higher_logic.rb @@ -195,7 +195,7 @@ def import_attachments original_filename = "#{a['VersionName']}.#{a['FileExtension']}" path = File.join(ATTACHMENT_DIR, original_filename) - if File.exists?(path) + if File.exist?(path) if post = Post.find(post_id_from_imported_post_id(a['MessageKey'])) filename = File.basename(original_filename) upload = create_upload(post.user.id, path, filename) diff --git a/script/import_scripts/ipboard.rb b/script/import_scripts/ipboard.rb index b849f75a47c0c..3f418ab53804f 100644 --- a/script/import_scripts/ipboard.rb +++ b/script/import_scripts/ipboard.rb @@ -213,7 +213,7 @@ def import_users post_create_action: proc do |newuser| if user['avatar_url'] && user['avatar_url'].length > 0 photo_path = AVATARS_DIR + user['avatar_url'] - if File.exists?(photo_path) + if File.exist?(photo_path) begin upload = create_upload(newuser.id, photo_path, File.basename(photo_path)) if upload && upload.persisted? diff --git a/script/import_scripts/ipboard3.rb b/script/import_scripts/ipboard3.rb index 4e7638633df2a..2ea180c901b32 100644 --- a/script/import_scripts/ipboard3.rb +++ b/script/import_scripts/ipboard3.rb @@ -87,7 +87,7 @@ def import_users new_user.update(suspended_at: DateTime.now, suspended_till: 100.years.from_now) elsif u["pp_main_photo"].present? path = File.join(UPLOADS_DIR, u["pp_main_photo"]) - if File.exists?(path) + if File.exist?(path) begin upload = create_upload(new_user.id, path, File.basename(path)) if upload.persisted? @@ -390,7 +390,7 @@ def clean_up(raw, user_id = -1) markdown.gsub!(/\[attachment=(\d+):.+\]/) do if a = mysql_query("SELECT attach_file, attach_location FROM attachments WHERE attach_id = #{$1}").first path = File.join(UPLOADS_DIR, a["attach_location"]) - if File.exists?(path) + if File.exist?(path) begin upload = create_upload(user_id, path, a["attach_file"]) return html_for_upload(upload, a["attach_file"]) if upload.persisted? diff --git a/script/import_scripts/lithium.rb b/script/import_scripts/lithium.rb index 161618a7c16e9..1d258e7cac0d8 100644 --- a/script/import_scripts/lithium.rb +++ b/script/import_scripts/lithium.rb @@ -842,7 +842,7 @@ def find_upload(user_id, attachment_id, real_filename) filename = attachment_id.to_s.rjust(4, "0") filename = File.join(ATTACHMENT_DIR, "000#{filename[0]}/#{filename}.dat") - unless File.exists?(filename) + unless File.exist?(filename) puts "Attachment file doesn't exist: #{filename}" return nil end @@ -953,9 +953,9 @@ def postprocess_post_raw(raw, user_id) # check to see if we have it if File.exist?(png) image = png - elsif File.exists?(jpg) + elsif File.exist?(jpg) image = jpg - elsif File.exists?(gif) + elsif File.exist?(gif) image = gif end diff --git a/script/import_scripts/mbox.rb b/script/import_scripts/mbox.rb index cee093033fcea..d712a5055d2c6 100644 --- a/script/import_scripts/mbox.rb +++ b/script/import_scripts/mbox.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if ARGV.length != 1 || !File.exists?(ARGV[0]) +if ARGV.length != 1 || !File.exist?(ARGV[0]) STDERR.puts '', 'Usage of mbox importer:', 'bundle exec ruby mbox.rb ' STDERR.puts '', "Use the settings file from #{File.expand_path('mbox/settings.yml', File.dirname(__FILE__))} as an example." exit 1 diff --git a/script/import_scripts/modx.rb b/script/import_scripts/modx.rb index 0cb4f6d8c4664..d2031bd336484 100644 --- a/script/import_scripts/modx.rb +++ b/script/import_scripts/modx.rb @@ -261,7 +261,7 @@ def not_find_upload(post, attachment_id) end filename = File.join(ATTACHMENT_DIR, row['user_id'].to_s.split('').join('/'), "#{row['file_id']}.attach") - unless File.exists?(filename) + unless File.exist?(filename) puts "Attachment file doesn't exist: #{filename}" return end diff --git a/script/import_scripts/ning.rb b/script/import_scripts/ning.rb index 712f07b86178f..30612ec969123 100644 --- a/script/import_scripts/ning.rb +++ b/script/import_scripts/ning.rb @@ -55,7 +55,7 @@ def execute def load_ning_json(arg) filename = File.join(JSON_FILES_DIR, arg) - raise RuntimeError.new("File #{filename} not found!") if !File.exists?(filename) + raise RuntimeError.new("File #{filename} not found!") if !File.exist?(filename) JSON.parse(repair_json(File.read(filename))).reverse end @@ -112,7 +112,7 @@ def import_users if u["profilePhoto"] && newuser.user_avatar.try(:custom_upload_id).nil? photo_path = file_full_path(u["profilePhoto"]) - if File.exists?(photo_path) + if File.exist?(photo_path) begin upload = create_upload(newuser.id, photo_path, File.basename(photo_path)) if upload.persisted? @@ -315,7 +315,7 @@ def process_ning_post_body(arg) ning_filename = matches[1] filename = File.join(JSON_FILES_DIR, ning_filename.split("?").first) - if !File.exists?(filename) + if !File.exist?(filename) puts "Attachment file doesn't exist: #{filename}" next s end @@ -339,7 +339,7 @@ def add_file_attachments(arg, file_names) file_names.each do |f| filename = File.join(JSON_FILES_DIR, f.split("?").first) - if !File.exists?(filename) + if !File.exist?(filename) puts "Attachment file doesn't exist: #{filename}" next end @@ -363,7 +363,7 @@ def add_photo(arg, file_name) # filename = File.join(JSON_FILES_DIR, file_name) filename = file_full_path(file_name) - if File.exists?(filename) + if File.exist?(filename) upload = create_upload(@system_user.id, filename, File.basename(filename)) if upload.nil? || !upload.valid? diff --git a/script/import_scripts/nodebb/nodebb.rb b/script/import_scripts/nodebb/nodebb.rb index 5fed857301d91..b29f5ee1c6cfa 100644 --- a/script/import_scripts/nodebb/nodebb.rb +++ b/script/import_scripts/nodebb/nodebb.rb @@ -216,7 +216,7 @@ def import_profile_picture(old_user, imported_user) filepath = File.join(ATTACHMENT_DIR, picture) filename = File.basename(picture) - unless File.exists?(filepath) + unless File.exist?(filepath) puts "Avatar file doesn't exist: #{filepath}" return nil end @@ -276,7 +276,7 @@ def import_profile_background(old_user, imported_user) filepath = File.join(ATTACHMENT_DIR, picture) filename = File.basename(picture) - unless File.exists?(filepath) + unless File.exist?(filepath) puts "Background file doesn't exist: #{filepath}" return nil end @@ -481,7 +481,7 @@ def import_attachments # if file exists # upload attachment and return html for it - if File.exists?(filepath) + if File.exist?(filepath) filename = File.basename(filepath) upload = create_upload(post.user_id, filepath, filename) diff --git a/script/import_scripts/phpbb3.rb b/script/import_scripts/phpbb3.rb index 3808b511b1704..4ee79d14ed08e 100644 --- a/script/import_scripts/phpbb3.rb +++ b/script/import_scripts/phpbb3.rb @@ -3,7 +3,7 @@ # Importer for phpBB 3.0 and 3.1 # Documentation: https://meta.discourse.org/t/importing-from-phpbb3/30810 -if ARGV.length != 1 || !File.exists?(ARGV[0]) +if ARGV.length != 1 || !File.exist?(ARGV[0]) STDERR.puts '', 'Usage of phpBB3 importer:', 'bundle exec ruby phpbb3.rb ' STDERR.puts '', "Use the settings file from #{File.expand_path('phpbb3/settings.yml', File.dirname(__FILE__))} as an example." STDERR.puts '', 'Still having problems? Take a look at https://meta.discourse.org/t/importing-from-phpbb3/30810' diff --git a/script/import_scripts/smf1.rb b/script/import_scripts/smf1.rb index 5f83eef673414..90ec314ea9766 100644 --- a/script/import_scripts/smf1.rb +++ b/script/import_scripts/smf1.rb @@ -411,7 +411,7 @@ def import_attachments next unless post = PostCustomField.joins(:post).find_by(name: "import_id", value: u["id_msg"].to_s)&.post path = File.join(UPLOADS_DIR, "#{u["id_attach"]}_#{u["file_hash"]}") - next unless File.exists?(path) && File.size(path) > 0 + next unless File.exist?(path) && File.size(path) > 0 if upload = create_upload(post.user_id, path, u["filename"]) html = html_for_upload(upload, u["filename"]) diff --git a/script/import_scripts/smf2.rb b/script/import_scripts/smf2.rb index 9885f1edc327e..a70faff4cb92a 100644 --- a/script/import_scripts/smf2.rb +++ b/script/import_scripts/smf2.rb @@ -303,7 +303,7 @@ def find_smf_attachment_path(attachment_id, file_hash, filename) [ filename, "#{attachment_id}_#{file_hash}", legacy_name ] .map { |name| File.join(options.smfroot, 'attachments', name) } - .detect { |file| File.exists?(file) } + .detect { |file| File.exist?(file) } end def decode_entities(*args) diff --git a/script/import_scripts/vanilla_mysql.rb b/script/import_scripts/vanilla_mysql.rb index da20a58257de4..d0a5e34893486 100644 --- a/script/import_scripts/vanilla_mysql.rb +++ b/script/import_scripts/vanilla_mysql.rb @@ -156,7 +156,7 @@ def import_users end def import_avatars - if ATTACHMENTS_BASE_DIR && File.exists?(ATTACHMENTS_BASE_DIR) + if ATTACHMENTS_BASE_DIR && File.exist?(ATTACHMENTS_BASE_DIR) puts "", "importing user avatars" User.find_each do |u| @@ -183,7 +183,7 @@ def import_avatars next end - if !File.exists?(photo_path) + if !File.exist?(photo_path) puts "Path to avatar file not found! Skipping. #{photo_path}" next end @@ -214,13 +214,13 @@ def find_photo_file(path, base_filename) base_guess = base_filename.dup full_guess = File.join(path, base_guess) # often an exact match exists - return full_guess if File.exists?(full_guess) + return full_guess if File.exist?(full_guess) # Otherwise, the file exists but with a prefix: # The p prefix seems to be the full file, so try to find that one first. ['p', 't', 'n'].each do |prefix| full_guess = File.join(path, "#{prefix}#{base_guess}") - return full_guess if File.exists?(full_guess) + return full_guess if File.exist?(full_guess) end # Didn't find it. @@ -554,7 +554,7 @@ def create_permalinks end def import_attachments - if ATTACHMENTS_BASE_DIR && File.exists?(ATTACHMENTS_BASE_DIR) + if ATTACHMENTS_BASE_DIR && File.exist?(ATTACHMENTS_BASE_DIR) puts "", "importing attachments" start = Time.now @@ -586,7 +586,7 @@ def import_attachments path.gsub!("s3://uploads/", "") file_path = "#{ATTACHMENTS_BASE_DIR}/#{path}" - if File.exists?(file_path) + if File.exist?(file_path) upload = create_upload(post.user.id, file_path, File.basename(file_path)) if upload && upload.errors.empty? # upload.url @@ -607,7 +607,7 @@ def import_attachments file_path = "#{ATTACHMENTS_BASE_DIR}/#{attachment_id}" - if File.exists?(file_path) + if File.exist?(file_path) upload = create_upload(post.user.id, file_path, File.basename(file_path)) if upload && upload.errors.empty? upload.url diff --git a/script/import_scripts/vbulletin.rb b/script/import_scripts/vbulletin.rb index d998daa916d06..9107823d3f0cb 100644 --- a/script/import_scripts/vbulletin.rb +++ b/script/import_scripts/vbulletin.rb @@ -426,7 +426,7 @@ def find_upload(post, attachment_id) real_filename = row['filename'] real_filename.prepend SecureRandom.hex if real_filename[0] == '.' - unless File.exists?(filename) + unless File.exist?(filename) if row['dbsize'].to_i == 0 puts "Attachment file #{row['filedataid']} doesn't exist" return nil diff --git a/script/import_scripts/vbulletin5.rb b/script/import_scripts/vbulletin5.rb index bdf80dcd3b180..5e5696e4f0f65 100644 --- a/script/import_scripts/vbulletin5.rb +++ b/script/import_scripts/vbulletin5.rb @@ -138,7 +138,7 @@ def import_profile_picture(old_user, imported_user) upload = UploadCreator.new(file, picture["filename"]).create_for(imported_user.id) else filename = File.join(AVATAR_DIR, picture['filename']) - unless File.exists?(filename) + unless File.exist?(filename) puts "Avatar file doesn't exist: #{filename}" return nil end @@ -366,7 +366,7 @@ def import_attachments real_filename = upload['filename'] real_filename.prepend SecureRandom.hex if real_filename[0] == '.' - unless File.exists?(filename) + unless File.exist?(filename) # attachments can be on filesystem or in database # try to retrieve from database if the file did not exist on filesystem if upload['dbsize'].to_i == 0 diff --git a/spec/components/common_passwords/common_passwords_spec.rb b/spec/components/common_passwords/common_passwords_spec.rb index deccf6a5d52fb..c68620d6e9ea9 100644 --- a/spec/components/common_passwords/common_passwords_spec.rb +++ b/spec/components/common_passwords/common_passwords_spec.rb @@ -5,7 +5,7 @@ describe CommonPasswords do it "the passwords file should exist" do - expect(File.exists?(described_class::PASSWORD_FILE)).to eq(true) + expect(File.exist?(described_class::PASSWORD_FILE)).to eq(true) end describe "#common_password?" do diff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rb index 8e68bf7ae84bd..40ce9e49b820d 100644 --- a/spec/components/oneboxer_spec.rb +++ b/spec/components/oneboxer_spec.rb @@ -5,7 +5,7 @@ describe Oneboxer do def response(file) file = File.join("spec", "fixtures", "onebox", "#{file}.response") - File.exists?(file) ? File.read(file) : "" + File.exist?(file) ? File.read(file) : "" end it "returns blank string for an invalid onebox" do diff --git a/spec/components/plugin/instance_spec.rb b/spec/components/plugin/instance_spec.rb index 506ac7e09ed1d..fd3c386452273 100644 --- a/spec/components/plugin/instance_spec.rb +++ b/spec/components/plugin/instance_spec.rb @@ -230,11 +230,11 @@ def enabled? # calls ensure_assets! make sure they are there expect(plugin.assets.count).to eq(1) plugin.assets.each do |a, opts| - expect(File.exists?(a)).to eq(true) + expect(File.exist?(a)).to eq(true) end # ensure it cleans up all crap in autogenerated directory - expect(File.exists?(junk_file)).to eq(false) + expect(File.exist?(junk_file)).to eq(false) end it "registers auth providers correctly" do diff --git a/spec/lib/backup_restore/local_backup_store_spec.rb b/spec/lib/backup_restore/local_backup_store_spec.rb index 5247daf28bdd4..3cf1ea4251813 100644 --- a/spec/lib/backup_restore/local_backup_store_spec.rb +++ b/spec/lib/backup_restore/local_backup_store_spec.rb @@ -36,16 +36,16 @@ def create_backups end def remove_backups - @paths.each { |path| File.delete(path) if File.exists?(path) } + @paths.each { |path| File.delete(path) if File.exist?(path) } @paths.clear end def create_file(db_name:, filename:, last_modified:, size_in_bytes:) path = File.join(@root_directory, db_name) - Dir.mkdir(path) unless Dir.exists?(path) + Dir.mkdir(path) unless Dir.exist?(path) path = File.join(path, filename) - return if File.exists?(path) + return if File.exist?(path) @paths << path FileUtils.touch(path) diff --git a/spec/lib/backup_restore/shared_examples_for_backup_store.rb b/spec/lib/backup_restore/shared_examples_for_backup_store.rb index 726fd511411b9..21f0a515bae7e 100644 --- a/spec/lib/backup_restore/shared_examples_for_backup_store.rb +++ b/spec/lib/backup_restore/shared_examples_for_backup_store.rb @@ -174,7 +174,7 @@ destination_path = File.join(path, File.basename(filename)) store.download_file(filename, destination_path) - expect(File.exists?(destination_path)).to eq(true) + expect(File.exist?(destination_path)).to eq(true) expect(File.size(destination_path)).to eq(backup1.size) end end diff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rb index 4ab612b33f037..a0fc0ec4ba68b 100644 --- a/spec/lib/upload_recovery_spec.rb +++ b/spec/lib/upload_recovery_spec.rb @@ -41,7 +41,7 @@ [ public_path, public_path.sub("uploads", "uploads/tombstone") - ].each { |path| File.delete(path) if File.exists?(path) } + ].each { |path| File.delete(path) if File.exist?(path) } end end diff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rb index 4139e83b8906c..2fc1b0f660194 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -28,7 +28,7 @@ expect(cropped_size).to be > 50 ensure - File.delete(tmp_path) if File.exists?(tmp_path) + File.delete(tmp_path) if File.exist?(tmp_path) end end @@ -73,7 +73,7 @@ expect(new_size).not_to eq(0) ensure - File.delete(original_path) if File.exists?(original_path) + File.delete(original_path) if File.exist?(original_path) end end @@ -124,7 +124,7 @@ ) end.to raise_error(RuntimeError, /improper image header/) ensure - File.delete(tmp_path) if File.exists?(tmp_path) + File.delete(tmp_path) if File.exist?(tmp_path) end end end @@ -146,7 +146,7 @@ expect(File.size(tmp_path)).to be < 2300 ensure - File.delete(tmp_path) if File.exists?(tmp_path) + File.delete(tmp_path) if File.exist?(tmp_path) end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e6fe72fac573c..579a0c61f23ff 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -425,7 +425,7 @@ def unfreeze_time def file_from_fixtures(filename, directory = "images") SpecSecureRandom.value ||= SecureRandom.hex - FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless Dir.exists?(file_from_fixtures_tmp_folder) + FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless Dir.exist?(file_from_fixtures_tmp_folder) tmp_file_path = File.join(file_from_fixtures_tmp_folder, SecureRandom.hex << filename) FileUtils.cp("#{Rails.root}/spec/fixtures/#{directory}/#{filename}", tmp_file_path) File.new(tmp_file_path) diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb index 6e3c06ec49263..673d42dee28e5 100644 --- a/spec/requests/admin/backups_controller_spec.rb +++ b/spec/requests/admin/backups_controller_spec.rb @@ -37,7 +37,7 @@ def map_preloaded after do Discourse.redis.flushdb - @paths&.each { |path| File.delete(path) if File.exists?(path) } + @paths&.each { |path| File.delete(path) if File.exist?(path) } @paths = nil end @@ -133,14 +133,14 @@ def map_preloaded begin path = backup_path(backup_filename) create_backup_files(backup_filename) - expect(File.exists?(path)).to eq(true) + expect(File.exist?(path)).to eq(true) expect do delete "/admin/backups/#{backup_filename}.json" end.to change { UserHistory.where(action: UserHistory.actions[:backup_destroy]).count }.by(1) expect(response.status).to eq(200) - expect(File.exists?(path)).to eq(false) + expect(File.exist?(path)).to eq(false) end end diff --git a/spec/requests/api/backups_spec.rb b/spec/requests/api/backups_spec.rb index 27317a41f1185..867a840d7a0ff 100644 --- a/spec/requests/api/backups_spec.rb +++ b/spec/requests/api/backups_spec.rb @@ -29,7 +29,7 @@ def backup_path(filename) after do Discourse.redis.flushdb - @paths&.each { |path| File.delete(path) if File.exists?(path) } + @paths&.each { |path| File.delete(path) if File.exist?(path) } @paths = nil end