mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 10:56:11 +02:00
Change to use File.join instead of string concatenation
because File.join makes the purpose of code clear and do it safely
This commit is contained in:
parent
c4eb06f5ba
commit
7b65e03cc8
@ -58,19 +58,19 @@ class Fluentd
|
||||
end
|
||||
|
||||
def config_backup_dir
|
||||
dir = FluentdUI.data_dir + "/#{Rails.env}_confg_backups"
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_confg_backups")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def running_config_backup_dir
|
||||
dir = FluentdUI.data_dir + "/#{Rails.env}_running_confg_backup"
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_running_confg_backup")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def running_config_backup_file
|
||||
running_config_backup_dir + "/running.conf"
|
||||
File.join(running_config_backup_dir, "running.conf")
|
||||
end
|
||||
|
||||
# define these methods on each Agent class
|
||||
|
||||
@ -64,7 +64,7 @@ class Fluentd
|
||||
end
|
||||
|
||||
def backup_files
|
||||
Dir.glob("#{config_backup_dir}/*")
|
||||
Dir.glob(File.join("#{config_backup_dir}", "*.conf"))
|
||||
end
|
||||
|
||||
def backup_files_in_old_order
|
||||
@ -80,7 +80,7 @@ class Fluentd
|
||||
def backup_config
|
||||
return unless File.exists? config_file
|
||||
|
||||
FileUtils.cp config_file, config_backup_dir + "/#{Time.zone.now.strftime('%Y%m%d_%H%M%S')}.conf"
|
||||
FileUtils.cp config_file, File.join(config_backup_dir, "#{Time.zone.now.strftime('%Y%m%d_%H%M%S')}.conf")
|
||||
|
||||
remove_over_backup_files
|
||||
end
|
||||
|
||||
@ -49,7 +49,7 @@ describe 'Fluentd::Agent::LocalCommon' do
|
||||
before do
|
||||
Fluentd::Agent::LocalCommon::MAX_BACKUP_FILE_NUM.times do |i|
|
||||
backpued_time = now - (i + 1).hours
|
||||
FileUtils.touch daemon.agent.config_backup_dir + "/#{backpued_time.strftime('%Y%m%d_%H%M%S')}.conf"
|
||||
FileUtils.touch File.join(daemon.agent.config_backup_dir , "#{backpued_time.strftime('%Y%m%d_%H%M%S')}.conf")
|
||||
end
|
||||
|
||||
daemon.agent.config_write config_contents #add before conf
|
||||
@ -61,7 +61,7 @@ describe 'Fluentd::Agent::LocalCommon' do
|
||||
end
|
||||
|
||||
it 'backed up old conf' do
|
||||
backup_file = daemon.agent.config_backup_dir + "/#{now.strftime('%Y%m%d_%H%M%S')}.conf"
|
||||
backup_file = File.join(daemon.agent.config_backup_dir, "#{now.strftime('%Y%m%d_%H%M%S')}.conf")
|
||||
expect(File.exists? backup_file).to be_truthy
|
||||
expect(File.read(backup_file)).to eq config_contents
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user