Skip to content

Commit 1d558c3

Browse files
authored
Fix instances of deprecated class methods (#15183)
Replace ::File.exists? for ::File.exist?
1 parent cb19d4e commit 1d558c3

23 files changed

+48
-43
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ AllCops:
2020
DisplayCopNames: true
2121
UseCache: false
2222

23+
#################### Lint ###########################
24+
##### Enabled Cops #####
25+
Lint/DeprecatedClassMethods:
26+
Enabled: true
27+
2328
#################### Layout ###########################
2429
##### Enabled Cops #####
2530
Layout/TrailingWhitespace:

lib/bootstrap/bundler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def invoke!(options = {})
113113

114114
require "fileutils"
115115
# create Gemfile from template iff it does not exist
116-
unless ::File.exists?(Environment::GEMFILE_PATH)
116+
unless ::File.exist?(Environment::GEMFILE_PATH)
117117
FileUtils.copy(
118118
::File.join(Environment::LOGSTASH_HOME, "Gemfile.template"), Environment::GEMFILE_PATH
119119
)
120120
end
121121
# create Gemfile.jruby-1.9.lock from template iff a template exists it itself does not exist
122122
lock_template = ::File.join(ENV["LOGSTASH_HOME"], "Gemfile.jruby-3.1.lock.release")
123-
if ::File.exists?(lock_template) && !::File.exists?(Environment::LOCKFILE)
123+
if ::File.exist?(lock_template) && !::File.exist?(Environment::LOCKFILE)
124124
FileUtils.copy(lock_template, Environment::LOCKFILE)
125125
end
126126

lib/bootstrap/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def ruby_engine
5454
def oss_only?
5555
return true if ENV['OSS']=="true"
5656

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

6060
def win_platform?

lib/pluginmanager/generate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def transform_r(source, target)
6363
target_entry = File.join(target, entry)
6464

6565
if File.directory?(source_entry)
66-
FileUtils.mkdir(target_entry) unless File.exists?(target_entry)
66+
FileUtils.mkdir(target_entry) unless File.exist?(target_entry)
6767
transform_r(source_entry, target_entry)
6868
else
6969
# copy the new file, in case of being an .erb file should render first

lib/pluginmanager/prepare_offline_pack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def execute
4545
signal_error("Package creation cancelled: You must specify the zip extension for the provided filename: #{output}.")
4646
end
4747

48-
if ::File.exists?(output)
48+
if ::File.exist?(output)
4949
if overwrite?
5050
File.delete(output)
5151
else

logstash-core/lib/logstash/agent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def id
240240
return @id if @id
241241

242242
uuid = nil
243-
if ::File.exists?(id_path)
243+
if ::File.exist?(id_path)
244244
begin
245245
uuid = ::File.open(id_path) {|f| f.each_line.first.chomp }
246246
rescue => e

logstash-core/lib/logstash/config/mixin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def validate_value(value, validator)
566566
#return false, "Require absolute path, got relative path #{value.first}?"
567567
#end
568568

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

logstash-core/lib/logstash/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
require 'pathname'
2323
LogStash::ROOT = Pathname.new(File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..")).cleanpath.to_s
2424
LogStash::XPACK_PATH = File.join(LogStash::ROOT, "x-pack")
25-
LogStash::OSS = ENV["OSS"] == "true" || !File.exists?(LogStash::XPACK_PATH)
25+
LogStash::OSS = ENV["OSS"] == "true" || !File.exist?(LogStash::XPACK_PATH)
2626

2727
if !LogStash::OSS
2828
xpack_dir = File.join(LogStash::XPACK_PATH, "lib")

logstash-core/lib/logstash/settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def validate(value)
614614
class ExistingFilePath < Setting
615615
def initialize(name, default=nil, strict=true)
616616
super(name, ::String, default, strict) do |file_path|
617-
if !::File.exists?(file_path)
617+
if !::File.exist?(file_path)
618618
raise ::ArgumentError.new("File \"#{file_path}\" must exist but was not found.")
619619
else
620620
true

logstash-core/spec/logstash/agent_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@
457457

458458
# wait for file existence otherwise it will raise exception on Windows
459459
wait(timeout)
460-
.for { ::File.exists?(new_config_output) && !::File.read(new_config_output).chomp.empty? }
460+
.for { ::File.exist?(new_config_output) && !::File.read(new_config_output).chomp.empty? }
461461
.to eq(true)
462462
# ensure the converge_state_and_update method has updated metrics by
463463
# invoking the mutex

qa/integration/services/service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(name, settings)
3131

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

4343
def teardown
4444
puts "Tearing down #{@name} service"
45-
if File.exists?(@teardown_script)
45+
if File.exist?(@teardown_script)
4646
`#{Shellwords.escape(@teardown_script)}`
4747
raise "#{@teardown_script} FAILED with exit status #{$?}" unless $?.success?
4848
else

qa/integration/specs/deprecation_log_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
wait_logstash_process_terminate
6161

6262
deprecation_log_file = "#{temp_dir}/logstash-deprecation.log"
63-
expect(File.exists?(deprecation_log_file)).to be true
63+
expect(File.exist?(deprecation_log_file)).to be true
6464
deprecation_log_content = IO.read(deprecation_log_file)
6565
expect(deprecation_log_content =~ /\[deprecation.logstash.filters.ruby\].*Teleport/).to be > 0
6666
end

qa/integration/specs/env_variables_config_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
send_data(test_tcp_port, sample_data)
5656
output_file = File.join(test_path, "logstash_env_test.log")
5757
try(num_retries) do
58-
expect(File.exists?(output_file)).to be true
58+
expect(File.exist?(output_file)).to be true
5959
end
6060
# should have created the file using env variable with filters adding a tag based on env variable
6161
try(num_retries) do

qa/integration/specs/fatal_error_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
expect(@logstash.exit_code).to be 120
5353

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

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

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

qa/integration/specs/kafka_input_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
end
4949

5050
after do
51-
File.delete(file_output_path) if File.exists?(file_output_path)
51+
File.delete(file_output_path) if File.exist?(file_output_path)
5252
end
5353

5454
it "can ingest 37 apache log lines from Kafka broker" do

qa/integration/specs/mixed_codec_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
logstash_service.teardown
6969

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

@@ -92,7 +92,7 @@
9292
logstash_service.teardown
9393

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

@@ -112,7 +112,7 @@
112112
logstash_service.teardown
113113

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

qa/integration/specs/pipeline_log_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
@ls.spawn_logstash("-w", "1" , "-e", config)
6060
wait_logstash_process_terminate(@ls)
6161
plainlog_file = "#{temp_dir}/logstash-plain.log"
62-
expect(File.exists?(plainlog_file)).to be true
62+
expect(File.exist?(plainlog_file)).to be true
6363
expect(IO.read(plainlog_file) =~ /\[logstash.javapipeline\s*\]\[#{pipeline_name}\]/).to be > 0
6464
end
6565

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

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

@@ -103,12 +103,12 @@
103103
wait_logstash_process_terminate(@ls)
104104

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

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

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

182182
plainlog_file = "#{temp_dir}/logstash-plain.log"
183-
expect(File.exists?(plainlog_file)).to be true
183+
expect(File.exist?(plainlog_file)).to be true
184184
plaing_log_content = IO.read(plainlog_file)
185185
expect(plaing_log_content =~ /Pipeline started {"pipeline.id"=>"#{pipeline_name}"}/).to be > 0
186186
end

qa/integration/specs/plugin_name_log_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
@ls.spawn_logstash("-w", "1" , "-e", config)
5757
wait_logstash_process_terminate()
5858
plainlog_file = "#{temp_dir}/logstash-plain.log"
59-
expect(File.exists?(plainlog_file)).to be true
59+
expect(File.exist?(plainlog_file)).to be true
6060
#We know taht sleep plugin log debug lines
6161
expect(IO.read(plainlog_file) =~ /\[sleep_filter_123\] Sleeping {:delay=>1}/).to be > 0
6262
end

qa/integration/specs/settings_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535

3636
before(:each) {
37-
FileUtils.rm(@logstash_default_logs) if File.exists?(@logstash_default_logs)
37+
FileUtils.rm(@logstash_default_logs) if File.exist?(@logstash_default_logs)
3838
# backup the application settings file -- logstash.yml
3939
FileUtils.cp(@logstash_service.application_settings_file, "#{@logstash_service.application_settings_file}.original")
4040
}
@@ -78,14 +78,14 @@ def overwrite_settings(settings)
7878
try(num_retries) do
7979
expect(is_port_open?(test_port)).to be true
8080
end
81-
expect(File.exists?("#{temp_dir}/logstash-plain.log")).to be true
81+
expect(File.exist?("#{temp_dir}/logstash-plain.log")).to be true
8282
end
8383

8484
it "should read config from the specified dir in logstash.yml" do
8585
change_setting("path.config", temp_dir)
8686
test_config_path = File.join(temp_dir, "test.config")
8787
IO.write(test_config_path, tcp_config)
88-
expect(File.exists?(test_config_path)).to be true
88+
expect(File.exist?(test_config_path)).to be true
8989
@logstash_service.spawn_logstash
9090
@logstash_service.wait_for_logstash
9191
# check LS is up and running with new data path
@@ -97,7 +97,7 @@ def overwrite_settings(settings)
9797
it "should exit when config test_and_exit is set" do
9898
test_config_path = File.join(temp_dir, "test.config")
9999
IO.write(test_config_path, "#{tcp_config}")
100-
expect(File.exists?(test_config_path)).to be true
100+
expect(File.exist?(test_config_path)).to be true
101101
s = {}
102102
s["path.config"] = test_config_path
103103
s["config.test_and_exit"] = true
@@ -111,7 +111,7 @@ def overwrite_settings(settings)
111111

112112
# now with bad config
113113
IO.write(test_config_path, "#{tcp_config} filters {} ")
114-
expect(File.exists?(test_config_path)).to be true
114+
expect(File.exist?(test_config_path)).to be true
115115
@logstash_service.spawn_logstash
116116
try(num_retries) do
117117
expect(@logstash_service.exited?).to be true
@@ -151,7 +151,7 @@ def overwrite_settings(settings)
151151
expect(is_port_open?(test_port)).to be true
152152
end
153153

154-
expect(File.exists?(@logstash_default_logs)).to be true
154+
expect(File.exist?(@logstash_default_logs)).to be true
155155

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

178178
# make sure we log to console and not to any file
179-
expect(File.exists?(@logstash_default_logs)).to be false
179+
expect(File.exist?(@logstash_default_logs)).to be false
180180
end
181181
end

qa/integration/specs/slowlog_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
@ls.wait_for_logstash
5858
sleep 2 until @ls.exited?
5959
slowlog_file = "#{temp_dir}/logstash-slowlog-plain.log"
60-
expect(File.exists?(slowlog_file)).to be true
60+
expect(File.exist?(slowlog_file)).to be true
6161
expect(IO.read(slowlog_file).split("\n").size).to be >= 1
6262
end
6363
end

rakelib/artifacts.rake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ namespace "artifact" do
476476
end
477477

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

482482
# add build.rb to tar
@@ -513,15 +513,15 @@ namespace "artifact" do
513513
ensure_logstash_version_constant_defined
514514
zippath = "build/logstash#{zip_suffix}-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}#{platform}.zip"
515515
puts("[artifact:zip] building #{zippath}")
516-
File.unlink(zippath) if File.exists?(zippath)
516+
File.unlink(zippath) if File.exist?(zippath)
517517
Zip::File.open(zippath, Zip::File::CREATE) do |zipfile|
518518
files(exclude_paths).each do |path|
519519
path_in_zip = "logstash-#{LOGSTASH_VERSION}#{PACKAGE_SUFFIX}/#{path}"
520520
zipfile.add(path_in_zip, path)
521521
end
522522

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

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

682682
out.scripts[script_sym] = File.read(script_path)
683683
end

rakelib/vendor.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace "vendor" do
1919
task "jruby" do |task, args|
20-
system('./gradlew bootstrap') unless File.exists?(File.join("vendor", "jruby"))
20+
system('./gradlew bootstrap') unless File.exist?(File.join("vendor", "jruby"))
2121
end # jruby
2222

2323
namespace "force" do
@@ -27,7 +27,7 @@ namespace "vendor" do
2727
task "gems", [:bundle] do |task, args|
2828
require "bootstrap/environment"
2929

30-
if File.exists?(LogStash::Environment::LOCKFILE) # gradlew already bootstrap-ed
30+
if File.exist?(LogStash::Environment::LOCKFILE) # gradlew already bootstrap-ed
3131
puts("Skipping bundler install...")
3232
else
3333
puts("Invoking bundler install...")

x-pack/qa/integration/support/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

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

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

0 commit comments

Comments
 (0)