Commit 12b637e6 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Handle the case when input_dir is absent

It is possible that not only the `public` directory is absent,
but the whole path isn't valid, this commit handles that
parent 94750f41
...@@ -8,20 +8,24 @@ module Pages ...@@ -8,20 +8,24 @@ module Pages
PUBLIC_DIR = 'public' PUBLIC_DIR = 'public'
def initialize(input_dir) def initialize(input_dir)
@input_dir = File.realpath(input_dir) @input_dir = input_dir
@output_file = File.join(@input_dir, "@migrated.zip") # '@' to avoid any name collision with groups or projects
end end
def execute def execute
FileUtils.rm_f(@output_file) raise InvalidArchiveError unless valid_work_directory?
@input_dir = File.realpath(@input_dir)
output_file = File.join(@input_dir, "@migrated.zip") # '@' to avoid any name collision with groups or projects
FileUtils.rm_f(output_file)
count = 0 count = 0
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile| ::Zip::File.open(output_file, ::Zip::File::CREATE) do |zipfile|
write_entry(zipfile, PUBLIC_DIR) write_entry(zipfile, PUBLIC_DIR)
count = zipfile.entries.count count = zipfile.entries.count
end end
[@output_file, count] [output_file, count]
end end
private private
...@@ -79,5 +83,13 @@ module Pages ...@@ -79,5 +83,13 @@ module Pages
false false
end end
def valid_work_directory?
Dir.exist?(@input_dir)
rescue => e
Gitlab::ErrorTracking.track_exception(e, input_dir: @input_dir)
false
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment