Skip to content

Commit

Permalink
For RakeTaskLog, ensure that our file directory exists before creatin…
Browse files Browse the repository at this point in the history
…g a file in it
  • Loading branch information
Austio committed Feb 10, 2021
1 parent cd0266b commit d961ed2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/rake_ui/rake_task_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class RakeTaskLog < OpenStruct
TASK_HEADER_OUTPUT_DELIMITER = "-------------------------------"
FILE_ITEM_SEPARATOR = ": "

def self.create_tmp_file_dir
FileUtils.mkdir_p(REPOSITORY_DIR.to_s)
end

def self.truncate
FileUtils.rm_rf(Dir.glob(REPOSITORY_DIR.to_s + "/*"))
end
Expand All @@ -25,10 +29,12 @@ def self.build_from_file(log_file_name)
end

def self.build_new_for_command(name:, rake_definition_file:, rake_command:, raker_id:, args: nil, environment: nil)
create_tmp_file_dir

date = Time.now.strftime(ID_DATE_FORMAT)
id = "#{date}#{FILE_DELIMITER}#{raker_id}"
log_file_name = "#{id}.txt"
log_file_full_path = Rails.root.join("tmp", "rake_ui", log_file_name).to_s
log_file_full_path = REPOSITORY_DIR.join(log_file_name).to_s

File.open(log_file_full_path, "w+") do |f|
f.puts "id#{FILE_ITEM_SEPARATOR}#{id}"
Expand Down Expand Up @@ -57,6 +63,8 @@ def self.build_new_for_command(name:, rake_definition_file:, rake_command:, rake
end

def self.all
create_tmp_file_dir

Dir.entries(REPOSITORY_DIR).reject { |file|
file == "." || file == ".."
}.map do |log|
Expand Down

0 comments on commit d961ed2

Please sign in to comment.