Skip to content

Commit

Permalink
Fix instances of deprecated class methods (#15183)
Browse files Browse the repository at this point in the history
Replace ::File.exists? for ::File.exist?
  • Loading branch information
roaksoax authored Jul 17, 2023
1 parent cb19d4e commit 1d558c3
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ AllCops:
DisplayCopNames: true
UseCache: false

#################### Lint ###########################
##### Enabled Cops #####
Lint/DeprecatedClassMethods:
Enabled: true

#################### Layout ###########################
##### Enabled Cops #####
Layout/TrailingWhitespace:
Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def invoke!(options = {})

require "fileutils"
# create Gemfile from template iff it does not exist
unless ::File.exists?(Environment::GEMFILE_PATH)
unless ::File.exist?(Environment::GEMFILE_PATH)
FileUtils.copy(
::File.join(Environment::LOGSTASH_HOME, "Gemfile.template"), Environment::GEMFILE_PATH
)
end
# create Gemfile.jruby-1.9.lock from template iff a template exists it itself does not exist
lock_template = ::File.join(ENV["LOGSTASH_HOME"], "Gemfile.jruby-3.1.lock.release")
if ::File.exists?(lock_template) && !::File.exists?(Environment::LOCKFILE)
if ::File.exist?(lock_template) && !::File.exist?(Environment::LOCKFILE)
FileUtils.copy(lock_template, Environment::LOCKFILE)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def ruby_engine
def oss_only?
return true if ENV['OSS']=="true"

!File.exists?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack"))
!File.exist?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack"))
end

def win_platform?
Expand Down
2 changes: 1 addition & 1 deletion lib/pluginmanager/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def transform_r(source, target)
target_entry = File.join(target, entry)

if File.directory?(source_entry)
FileUtils.mkdir(target_entry) unless File.exists?(target_entry)
FileUtils.mkdir(target_entry) unless File.exist?(target_entry)
transform_r(source_entry, target_entry)
else
# copy the new file, in case of being an .erb file should render first
Expand Down
2 changes: 1 addition & 1 deletion lib/pluginmanager/prepare_offline_pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute
signal_error("Package creation cancelled: You must specify the zip extension for the provided filename: #{output}.")
end

if ::File.exists?(output)
if ::File.exist?(output)
if overwrite?
File.delete(output)
else
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def id
return @id if @id

uuid = nil
if ::File.exists?(id_path)
if ::File.exist?(id_path)
begin
uuid = ::File.open(id_path) {|f| f.each_line.first.chomp }
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def validate_value(value, validator)
#return false, "Require absolute path, got relative path #{value.first}?"
#end

if !File.exists?(value.first) # Check if the file exists
if !File.exist?(value.first) # Check if the file exists
return false, "File does not exist or cannot be opened #{value.first}"
end

Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require 'pathname'
LogStash::ROOT = Pathname.new(File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..")).cleanpath.to_s
LogStash::XPACK_PATH = File.join(LogStash::ROOT, "x-pack")
LogStash::OSS = ENV["OSS"] == "true" || !File.exists?(LogStash::XPACK_PATH)
LogStash::OSS = ENV["OSS"] == "true" || !File.exist?(LogStash::XPACK_PATH)

if !LogStash::OSS
xpack_dir = File.join(LogStash::XPACK_PATH, "lib")
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def validate(value)
class ExistingFilePath < Setting
def initialize(name, default=nil, strict=true)
super(name, ::String, default, strict) do |file_path|
if !::File.exists?(file_path)
if !::File.exist?(file_path)
raise ::ArgumentError.new("File \"#{file_path}\" must exist but was not found.")
else
true
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/spec/logstash/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@

# wait for file existence otherwise it will raise exception on Windows
wait(timeout)
.for { ::File.exists?(new_config_output) && !::File.read(new_config_output).chomp.empty? }
.for { ::File.exist?(new_config_output) && !::File.read(new_config_output).chomp.empty? }
.to eq(true)
# ensure the converge_state_and_update method has updated metrics by
# invoking the mutex
Expand Down
4 changes: 2 additions & 2 deletions qa/integration/services/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(name, settings)

def setup
puts "Setting up #{@name} service"
if File.exists?(@setup_script)
if File.exist?(@setup_script)
`#{Shellwords.escape(@setup_script)}`
raise "#{@setup_script} FAILED with exit status #{$?}" unless $?.success?
else
Expand All @@ -42,7 +42,7 @@ def setup

def teardown
puts "Tearing down #{@name} service"
if File.exists?(@teardown_script)
if File.exist?(@teardown_script)
`#{Shellwords.escape(@teardown_script)}`
raise "#{@teardown_script} FAILED with exit status #{$?}" unless $?.success?
else
Expand Down
2 changes: 1 addition & 1 deletion qa/integration/specs/deprecation_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
wait_logstash_process_terminate

deprecation_log_file = "#{temp_dir}/logstash-deprecation.log"
expect(File.exists?(deprecation_log_file)).to be true
expect(File.exist?(deprecation_log_file)).to be true
deprecation_log_content = IO.read(deprecation_log_file)
expect(deprecation_log_content =~ /\[deprecation.logstash.filters.ruby\].*Teleport/).to be > 0
end
Expand Down
2 changes: 1 addition & 1 deletion qa/integration/specs/env_variables_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
send_data(test_tcp_port, sample_data)
output_file = File.join(test_path, "logstash_env_test.log")
try(num_retries) do
expect(File.exists?(output_file)).to be true
expect(File.exist?(output_file)).to be true
end
# should have created the file using env variable with filters adding a tag based on env variable
try(num_retries) do
Expand Down
4 changes: 2 additions & 2 deletions qa/integration/specs/fatal_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
expect(@logstash.exit_code).to be 120

log_file = "#{logs_dir}/logstash-plain.log"
expect( File.exists?(log_file) ).to be true
expect( File.exist?(log_file) ).to be true
expect( File.read(log_file) ).to match /\[FATAL\]\[org.logstash.Logstash.*?java.lang.AssertionError: a fatal error/m
end

Expand All @@ -65,7 +65,7 @@
expect(@logstash.exit_code).to be 0 # normal exit

log_file = "#{logs_dir}/logstash-plain.log"
expect( File.exists?(log_file) ).to be true
expect( File.exist?(log_file) ).to be true
expect( File.read(log_file) ).to match /\[ERROR\]\[org.logstash.Logstash.*?uncaught exception \(in thread .*?java.io.EOFException: unexpected/m
end

Expand Down
2 changes: 1 addition & 1 deletion qa/integration/specs/kafka_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end

after do
File.delete(file_output_path) if File.exists?(file_output_path)
File.delete(file_output_path) if File.exist?(file_output_path)
end

it "can ingest 37 apache log lines from Kafka broker" do
Expand Down
6 changes: 3 additions & 3 deletions qa/integration/specs/mixed_codec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
logstash_service.teardown

plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")

Expand All @@ -92,7 +92,7 @@
logstash_service.teardown

plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")

Expand All @@ -112,7 +112,7 @@
logstash_service.teardown

plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")
end
Expand Down
14 changes: 7 additions & 7 deletions qa/integration/specs/pipeline_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
@ls.spawn_logstash("-w", "1" , "-e", config)
wait_logstash_process_terminate(@ls)
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
expect(IO.read(plainlog_file) =~ /\[logstash.javapipeline\s*\]\[#{pipeline_name}\]/).to be > 0
end

Expand All @@ -73,7 +73,7 @@
@ls.spawn_logstash("-w", "1" , "-e", config)
wait_logstash_process_terminate(@ls)
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
expect(IO.read(plainlog_file) =~ /Starting pipeline.*"pipeline.sources"=>\["config string"\]/).to be > 0
end

Expand All @@ -87,7 +87,7 @@
@ls.spawn_logstash("-w", "1", "-f", "#{initial_config_file}")
wait_logstash_process_terminate(@ls)
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
expect(IO.read(plainlog_file) =~ /Starting pipeline.*"pipeline.sources"=>\["#{initial_config_file}"\]/).to be > 0
end

Expand All @@ -103,12 +103,12 @@
wait_logstash_process_terminate(@ls)

pipeline_log_file = "#{temp_dir}/pipeline_#{pipeline_name}.log"
expect(File.exists?(pipeline_log_file)).to be true
expect(File.exist?(pipeline_log_file)).to be true
content = IO.read(pipeline_log_file)
expect(content =~ /Pipeline started {"pipeline.id"=>"#{pipeline_name}"}/).to be > 0

plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
plainlog_content = IO.read(plainlog_file)
expect(plainlog_content =~ /Pipeline started {"pipeline.id"=>"#{pipeline_name}"}/).to be_nil
end
Expand Down Expand Up @@ -177,10 +177,10 @@
wait_logstash_process_terminate(@ls)

pipeline_log_file = "#{temp_dir}/pipeline_#{pipeline_name}.log"
expect(File.exists?(pipeline_log_file)).to be false
expect(File.exist?(pipeline_log_file)).to be false

plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
plaing_log_content = IO.read(plainlog_file)
expect(plaing_log_content =~ /Pipeline started {"pipeline.id"=>"#{pipeline_name}"}/).to be > 0
end
Expand Down
2 changes: 1 addition & 1 deletion qa/integration/specs/plugin_name_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@ls.spawn_logstash("-w", "1" , "-e", config)
wait_logstash_process_terminate()
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exists?(plainlog_file)).to be true
expect(File.exist?(plainlog_file)).to be true
#We know taht sleep plugin log debug lines
expect(IO.read(plainlog_file) =~ /\[sleep_filter_123\] Sleeping {:delay=>1}/).to be > 0
end
Expand Down
14 changes: 7 additions & 7 deletions qa/integration/specs/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

before(:each) {
FileUtils.rm(@logstash_default_logs) if File.exists?(@logstash_default_logs)
FileUtils.rm(@logstash_default_logs) if File.exist?(@logstash_default_logs)
# backup the application settings file -- logstash.yml
FileUtils.cp(@logstash_service.application_settings_file, "#{@logstash_service.application_settings_file}.original")
}
Expand Down Expand Up @@ -78,14 +78,14 @@ def overwrite_settings(settings)
try(num_retries) do
expect(is_port_open?(test_port)).to be true
end
expect(File.exists?("#{temp_dir}/logstash-plain.log")).to be true
expect(File.exist?("#{temp_dir}/logstash-plain.log")).to be true
end

it "should read config from the specified dir in logstash.yml" do
change_setting("path.config", temp_dir)
test_config_path = File.join(temp_dir, "test.config")
IO.write(test_config_path, tcp_config)
expect(File.exists?(test_config_path)).to be true
expect(File.exist?(test_config_path)).to be true
@logstash_service.spawn_logstash
@logstash_service.wait_for_logstash
# check LS is up and running with new data path
Expand All @@ -97,7 +97,7 @@ def overwrite_settings(settings)
it "should exit when config test_and_exit is set" do
test_config_path = File.join(temp_dir, "test.config")
IO.write(test_config_path, "#{tcp_config}")
expect(File.exists?(test_config_path)).to be true
expect(File.exist?(test_config_path)).to be true
s = {}
s["path.config"] = test_config_path
s["config.test_and_exit"] = true
Expand All @@ -111,7 +111,7 @@ def overwrite_settings(settings)

# now with bad config
IO.write(test_config_path, "#{tcp_config} filters {} ")
expect(File.exists?(test_config_path)).to be true
expect(File.exist?(test_config_path)).to be true
@logstash_service.spawn_logstash
try(num_retries) do
expect(@logstash_service.exited?).to be true
Expand Down Expand Up @@ -151,7 +151,7 @@ def overwrite_settings(settings)
expect(is_port_open?(test_port)).to be true
end

expect(File.exists?(@logstash_default_logs)).to be true
expect(File.exist?(@logstash_default_logs)).to be true

resp = Manticore.get("http://localhost:#{http_port}/_node").body
node_info = JSON.parse(resp)
Expand All @@ -176,6 +176,6 @@ def overwrite_settings(settings)
expect(node_info["http_address"]).to eq("127.0.0.1:#{http_port}")

# make sure we log to console and not to any file
expect(File.exists?(@logstash_default_logs)).to be false
expect(File.exist?(@logstash_default_logs)).to be false
end
end
2 changes: 1 addition & 1 deletion qa/integration/specs/slowlog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@ls.wait_for_logstash
sleep 2 until @ls.exited?
slowlog_file = "#{temp_dir}/logstash-slowlog-plain.log"
expect(File.exists?(slowlog_file)).to be true
expect(File.exist?(slowlog_file)).to be true
expect(IO.read(slowlog_file).split("\n").size).to be >= 1
end
end
8 changes: 4 additions & 4 deletions rakelib/artifacts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ namespace "artifact" do
end

source_license_path = "licenses/#{license}.txt"
fail("Missing source license: #{source_license_path}") unless File.exists?(source_license_path)
fail("Missing source license: #{source_license_path}") unless File.exist?(source_license_path)
write_to_tar(tar, source_license_path, "logstash-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}/LICENSE.txt")

# add build.rb to tar
Expand Down Expand Up @@ -513,15 +513,15 @@ namespace "artifact" do
ensure_logstash_version_constant_defined
zippath = "build/logstash#{zip_suffix}-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}#{platform}.zip"
puts("[artifact:zip] building #{zippath}")
File.unlink(zippath) if File.exists?(zippath)
File.unlink(zippath) if File.exist?(zippath)
Zip::File.open(zippath, Zip::File::CREATE) do |zipfile|
files(exclude_paths).each do |path|
path_in_zip = "logstash-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}/#{path}"
zipfile.add(path_in_zip, path)
end

source_license_path = "licenses/#{license}.txt"
fail("Missing source license: #{source_license_path}") unless File.exists?(source_license_path)
fail("Missing source license: #{source_license_path}") unless File.exist?(source_license_path)
zipfile.add("logstash-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}/LICENSE.txt", source_license_path)

# add build.rb to zip
Expand Down Expand Up @@ -677,7 +677,7 @@ namespace "artifact" do
script = "#{stage}-#{action}" # like, "before-install"
script_sym = script.gsub("-", "_").to_sym
script_path = File.join(File.dirname(__FILE__), "..", "pkg", platform, "#{script}.sh")
next unless File.exists?(script_path)
next unless File.exist?(script_path)

out.scripts[script_sym] = File.read(script_path)
end
Expand Down
4 changes: 2 additions & 2 deletions rakelib/vendor.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace "vendor" do
task "jruby" do |task, args|
system('./gradlew bootstrap') unless File.exists?(File.join("vendor", "jruby"))
system('./gradlew bootstrap') unless File.exist?(File.join("vendor", "jruby"))
end # jruby

namespace "force" do
Expand All @@ -27,7 +27,7 @@ namespace "vendor" do
task "gems", [:bundle] do |task, args|
require "bootstrap/environment"

if File.exists?(LogStash::Environment::LOCKFILE) # gradlew already bootstrap-ed
if File.exist?(LogStash::Environment::LOCKFILE) # gradlew already bootstrap-ed
puts("Skipping bundler install...")
else
puts("Invoking bundler install...")
Expand Down
2 changes: 1 addition & 1 deletion x-pack/qa/integration/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

VERSIONS_YML_PATH = File.join(File.dirname(__FILE__), "..", "..", "..", "..", "versions.yml")
VERSION_PATH = File.join(File.dirname(__FILE__), "..", "..", "..", "VERSION")
VERSION = File.exists?(VERSIONS_YML_PATH) ? YAML.load_file(VERSIONS_YML_PATH)['logstash'] : File.read(VERSION_PATH).strip
VERSION = File.exist?(VERSIONS_YML_PATH) ? YAML.load_file(VERSIONS_YML_PATH)['logstash'] : File.read(VERSION_PATH).strip

def get_logstash_path
ENV["LOGSTASH_PATH"] || File.join(File.dirname(__FILE__), "../../../../")
Expand Down

0 comments on commit 1d558c3

Please sign in to comment.