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?
This commit is contained in:
Peter Zhu
2022-01-05 12:45:08 -05:00
committed by GitHub
parent 692ba188bf
commit c5fd8c42db
75 changed files with 140 additions and 140 deletions

View File

@ -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) }