Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix methods removed in Ruby 3.2 (#15459)

Peter Zhuc5fd8c42dbf8
diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb
index d65baac29cc..2d339e9f545 100644
--- a/app/controllers/user_avatars_controller.rb
+++ b/app/controllers/user_avatars_controller.rb
@@ -124,7 +124,7 @@ class UserAvatarsController < ApplicationController
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 262e8719207..44305b44720 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -56,7 +56,7 @@ module Jobs
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 4ff3f1fcb81..ba2442df774 100644
--- a/app/jobs/regular/export_user_archive.rb
+++ b/app/jobs/regular/export_user_archive.rb
@@ -70,7 +70,7 @@ module Jobs
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 c83db37cfae..c39ceaefd92 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -267,7 +267,7 @@ class GlobalSetting
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 2bd365b6432..d966f659aa1 100644
--- a/app/services/handle_chunk_upload.rb
+++ b/app/services/handle_chunk_upload.rb
@@ -21,7 +21,7 @@ class HandleChunkUpload
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 @@ class HandleChunkUpload
# 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 c52d2f8394d..9735e3eec0b 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 f3b61fd24cc..6866506f24b 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -10,7 +10,7 @@ require 'rubygems'
# 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 922380cf675..0998cf01b19 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 @@ Thread.new do
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 b00fca1883f..50b0a622974 100644
--- a/config/unicorn.conf.rb
+++ b/config/unicorn.conf.rb
@@ -71,7 +71,7 @@ before_fork do |server, worker|
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 8b5b3ac4162..a6b26aff7ff 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 bd8e49803b3..175f743aa90 100644
--- a/lib/autospec/manager.rb
+++ b/lib/autospec/manager.rb
@@ -295,7 +295,7 @@ class Autospec::Manager
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 ec76a240cd7..a50ed7593a3 100644
--- a/lib/autospec/qunit_runner.rb
+++ b/lib/autospec/qunit_runner.rb
@@ -152,7 +152,7 @@ module Autospec
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 54753e22ff5..8f24cdec984 100644
--- a/lib/autospec/reload_css.rb
+++ b/lib/autospec/reload_css.rb
@@ -40,7 +40,7 @@ class Autospec::ReloadCss
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 d9369789fb8..483d6f6473a 100644
--- a/lib/backup_restore/backup_file_handler.rb
+++ b/lib/backup_restore/backup_file_handler.rb
@@ -86,7 +86,7 @@ module BackupRestore
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 1b1cb977f5c..fd7f16b9f63 100644
--- a/lib/backup_restore/local_backup_store.rb
+++ b/lib/backup_restore/local_backup_store.rb
@@ -7,7 +7,7 @@ module BackupRestore
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 @@ module BackupRestore
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 002bbd0d285..02bc0e98bf0 100644
--- a/lib/backup_restore/meta_data_handler.rb
+++ b/lib/backup_restore/meta_data_handler.rb
@@ -42,7 +42,7 @@ module BackupRestore
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 2d6d46e2955..397fb5d0b08 100644
--- a/lib/demon/base.rb
+++ b/lib/demon/base.rb
@@ -151,7 +151,7 @@ class Demon::Base
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 4a2142b43c6..eb4a1d160bd 100644
--- a/lib/discourse_dev/config.rb
+++ b/lib/discourse_dev/config.rb
@@ -12,7 +12,7 @@ module DiscourseDev
@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 b858e996c61..8f5266a1914 100644
--- a/lib/faker/discourse_markdown.rb
+++ b/lib/faker/discourse_markdown.rb
@@ -72,7 +72,7 @@ module Faker
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 5d21449bcdb..eec747ba080 100644
--- a/lib/file_store/base_store.rb
+++ b/lib/file_store/base_store.rb
@@ -173,7 +173,7 @@ module FileStore
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 e71e3a6ba76..9e704efee98 100644
--- a/lib/file_store/local_store.rb
+++ b/lib/file_store/local_store.rb
@@ -14,11 +14,11 @@ module FileStore
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 @@ module FileStore
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 @@ module FileStore
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 757e9b969a2..4d0088ab8c6 100644
--- a/lib/i18n/locale_file_checker.rb
+++ b/lib/i18n/locale_file_checker.rb
@@ -49,7 +49,7 @@ class LocaleFileChecker
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 cdd054626a2..1a8524f338a 100644
--- a/lib/letter_avatar.rb
+++ b/lib/letter_avatar.rb
@@ -42,10 +42,10 @@ class LetterAvatar
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 1e9526aceda..50f4ae04e10 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -424,7 +424,7 @@ class Plugin::Instance
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 @@ class Plugin::Instance
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 @@ class Plugin::Instance
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 @@ class Plugin::Instance
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 855d1aca2c1..c870680dbd7 100644
--- a/lib/plugin_gem.rb
+++ b/lib/plugin_gem.rb
@@ -12,14 +12,14 @@ module PluginGem
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 80239130c3b..c62ee62c81b 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -140,7 +140,7 @@ class S3Inventory
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 @@ class S3Inventory
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 @@ class S3Inventory
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 a9b9c631b1f..43b5bdf1ed2 100644
--- a/lib/stylesheet/manager.rb
+++ b/lib/stylesheet/manager.rb
@@ -107,7 +107,7 @@ class Stylesheet::Manager
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 @@ class Stylesheet::Manager
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 @@ class Stylesheet::Manager
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 @@ class Stylesheet::Manager
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 0b89cd8dc6c..b88730f1653 100644
--- a/lib/stylesheet/manager/builder.rb
+++ b/lib/stylesheet/manager/builder.rb
@@ -12,7 +12,7 @@ class Stylesheet::Manager::Builder
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 39bf7a3bf71..c8025a92cea 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 07b0046aa39..dc92250cdd5 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 2c09ce9dd04..70570efe0bd 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 0b75aae5224..eb3cf8f737a 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 7b7258d6d47..2c54f9f6a49 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 ba984bd4037..9a05d5fd96c 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[<path to ZIP file>]"
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[<path to ZIP file>]"
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 4f48dff0c0a..cc686ddf223 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 924ee605030..4a043ca1517 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 3b7a42e9b5e..1bcffa570d8 100644
--- a/lib/temporary_db.rb
+++ b/lib/temporary_db.rb
@@ -24,7 +24,7 @@ class TemporaryDb
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 d1ab78d791a..86f6c6c73cf 100644
--- a/script/bench.rb
+++ b/script/bench.rb
@@ -112,7 +112,7 @@ unless $? == 0
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 da2a9c6a114..e1ab58c83c3 100644
--- a/script/bulk_import/discourse_merger.rb
+++ b/script/bulk_import/discourse_merger.rb
@@ -359,7 +359,7 @@ class BulkImport::DiscourseMerger < BulkImport::Base
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 cb85b853f93..d01eed3af03 100644
--- a/script/bulk_import/vanilla.rb
+++ b/script/bulk_import/vanilla.rb
@@ -203,7 +203,7 @@ class BulkImport::Vanilla < BulkImport::Base
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 @@ class BulkImport::Vanilla < BulkImport::Base
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 @@ class BulkImport::Vanilla < BulkImport::Base
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 @@ class BulkImport::Vanilla < BulkImport::Base
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 @@ class BulkImport::Vanilla < BulkImport::Base
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 @@ class BulkImport::Vanilla < BulkImport::Base
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 8a57522002c..511d7a8cea2 100644
--- a/script/bulk_import/vbulletin.rb
+++ b/script/bulk_import/vbulletin.rb
@@ -531,7 +531,7 @@ class BulkImport::VBulletin < BulkImport::Base
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 @@ class BulkImport::VBulletin < BulkImport::Base
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 @@ class BulkImport::VBulletin < BulkImport::Base
# 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 507eb3d5d2c..9be967c25c4 100644
--- a/script/bulk_import/vbulletin5.rb
+++ b/script/bulk_import/vbulletin5.rb
@@ -616,7 +616,7 @@ class BulkImport::VBulletin5 < BulkImport::Base
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 035d625c293..f2e05811bac 100644
--- a/script/import_scripts/answerhub.rb
+++ b/script/import_scripts/answerhub.rb
@@ -367,7 +367,7 @@ class ImportScripts::AnswerHub < ImportScripts::Base
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 @@ class ImportScripts::AnswerHub < ImportScripts::Base
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 @@ class ImportScripts::AnswerHub < ImportScripts::Base
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 2b10e0c25ad..28bfd8ee3bf 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 1db8c2c0d8c..2cd0698d123 100644
--- a/script/import_scripts/bbpress.rb
+++ b/script/import_scripts/bbpress.rb
@@ -316,7 +316,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
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 edced0e7ab3..1b3cb5b8cbc 100644
--- a/script/import_scripts/discuz_x.rb
+++ b/script/import_scripts/discuz_x.rb
@@ -927,7 +927,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
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 a10615fe320..23348c055bf 100644
--- a/script/import_scripts/drupal.rb
+++ b/script/import_scripts/drupal.rb
@@ -428,7 +428,7 @@ class ImportScripts::Drupal < ImportScripts::Base
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 3b72e7d61ad..d69f21e01bd 100644
--- a/script/import_scripts/drupal_json.rb
+++ b/script/import_scripts/drupal_json.rb
@@ -23,7 +23,7 @@ class ImportScripts::DrupalJson < ImportScripts::Base
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 ee22dd9cbca..d66eed12cc1 100644
--- a/script/import_scripts/friendsmegplus.rb
+++ b/script/import_scripts/friendsmegplus.rb
@@ -178,7 +178,7 @@ class ImportScripts::FMGP < ImportScripts::Base
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 495cc50c0ed..50f8613e683 100644
--- a/script/import_scripts/getsatisfaction.rb
+++ b/script/import_scripts/getsatisfaction.rb
@@ -69,7 +69,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
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 359114e6627..ab7bb303895 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 1f5b1d9599e..fe6e19641dd 100644
--- a/script/import_scripts/higher_logic.rb
+++ b/script/import_scripts/higher_logic.rb
@@ -195,7 +195,7 @@ class ImportScripts::HigherLogic < ImportScripts::Base
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 b849f75a47c..3f418ab5380 100644
--- a/script/import_scripts/ipboard.rb
+++ b/script/import_scripts/ipboard.rb
@@ -213,7 +213,7 @@ EOM
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 4e7638633df..2ea180c901b 100644
--- a/script/import_scripts/ipboard3.rb
+++ b/script/import_scripts/ipboard3.rb
@@ -87,7 +87,7 @@ class ImportScripts::IPBoard3 < ImportScripts::Base
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 @@ class ImportScripts::IPBoard3 < ImportScripts::Base
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 161618a7c16..1d258e7cac0 100644
--- a/script/import_scripts/lithium.rb
+++ b/script/import_scripts/lithium.rb
@@ -842,7 +842,7 @@ SQL
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 @@ SQL
# 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 cee093033fc..d712a5055d2 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 <path/to/settings.yml>'
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 0cb4f6d8c46..d2031bd3364 100644
--- a/script/import_scripts/modx.rb
+++ b/script/import_scripts/modx.rb
@@ -261,7 +261,7 @@ FROM #{TABLE_PREFIX}discuss_users
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 712f07b8617..30612ec9691 100644
--- a/script/import_scripts/ning.rb
+++ b/script/import_scripts/ning.rb
@@ -55,7 +55,7 @@ class ImportScripts::Ning < ImportScripts::Base
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 @@ class ImportScripts::Ning < ImportScripts::Base
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 @@ class ImportScripts::Ning < ImportScripts::Base
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 @@ class ImportScripts::Ning < ImportScripts::Base
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 @@ class ImportScripts::Ning < ImportScripts::Base
# 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 5fed857301d..b29f5ee1c6c 100644
--- a/script/import_scripts/nodebb/nodebb.rb
+++ b/script/import_scripts/nodebb/nodebb.rb
@@ -216,7 +216,7 @@ class ImportScripts::NodeBB < ImportScripts::Base
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 @@ class ImportScripts::NodeBB < ImportScripts::Base
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 @@ class ImportScripts::NodeBB < ImportScripts::Base
# 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 3808b511b17..4ee79d14ed0 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 <path/to/settings.yml>'
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 5f83eef6734..90ec314ea97 100644
--- a/script/import_scripts/smf1.rb
+++ b/script/import_scripts/smf1.rb
@@ -411,7 +411,7 @@ class ImportScripts::Smf1 < ImportScripts::Base
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 9885f1edc32..a70faff4cb9 100644
--- a/script/import_scripts/smf2.rb
+++ b/script/import_scripts/smf2.rb
@@ -303,7 +303,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
[ 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 da20a58257d..d0a5e348934 100644
--- a/script/import_scripts/vanilla_mysql.rb
+++ b/script/import_scripts/vanilla_mysql.rb
@@ -156,7 +156,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
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 d998daa916d..9107823d3f0 100644
--- a/script/import_scripts/vbulletin.rb
+++ b/script/import_scripts/vbulletin.rb
@@ -426,7 +426,7 @@ EOM
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 bdf80dcd3b1..5e5696e4f0f 100644
--- a/script/import_scripts/vbulletin5.rb
+++ b/script/import_scripts/vbulletin5.rb
@@ -138,7 +138,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
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 @@ class ImportScripts::VBulletin < ImportScripts::Base
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 deccf6a5d52..c68620d6e9e 100644
--- a/spec/components/common_passwords/common_passwords_spec.rb
+++ b/spec/components/common_passwords/common_passwords_spec.rb
@@ -5,7 +5,7 @@ require "rails_helper"
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 8e68bf7ae84..40ce9e49b82 100644
--- a/spec/components/oneboxer_spec.rb
+++ b/spec/components/oneboxer_spec.rb
@@ -5,7 +5,7 @@ require 'rails_helper'
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 506ac7e09ed..fd3c3864522 100644
--- a/spec/components/plugin/instance_spec.rb
+++ b/spec/components/plugin/instance_spec.rb
@@ -230,11 +230,11 @@ describe Plugin::Instance do
# 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 5247daf28bd..3cf1ea42518 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 @@ describe BackupRestore::LocalBackupStore do
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 726fd511411..21f0a515bae 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 @@ shared_examples "backup store" do
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 4ab612b33f0..a0fc0ec4ba6 100644
--- a/spec/lib/upload_recovery_spec.rb
+++ b/spec/lib/upload_recovery_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe UploadRecovery do
[
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 4139e83b890..2fc1b0f6601 100644
--- a/spec/models/optimized_image_spec.rb
+++ b/spec/models/optimized_image_spec.rb
@@ -28,7 +28,7 @@ describe OptimizedImage do
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 @@ describe OptimizedImage do
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 @@ describe OptimizedImage do
)
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 @@ describe OptimizedImage do
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 e6fe72fac57..579a0c61f23 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -425,7 +425,7 @@ end
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 6e3c06ec492..673d42dee28 100644
--- a/spec/requests/admin/backups_controller_spec.rb
+++ b/spec/requests/admin/backups_controller_spec.rb
@@ -37,7 +37,7 @@ RSpec.describe Admin::BackupsController do
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 @@ RSpec.describe Admin::BackupsController do
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 27317a41f11..867a840d7a0 100644
--- a/spec/requests/api/backups_spec.rb
+++ b/spec/requests/api/backups_spec.rb
@@ -29,7 +29,7 @@ describe 'backups' do
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