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:
鳥井 雪 2014-12-17 18:19:01 +09:00
parent c4eb06f5ba
commit 7b65e03cc8
3 changed files with 7 additions and 7 deletions

View File

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

View File

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

View File

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