Commit 1b77e3ec authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-fix-geo-transfer-tempfile' into 'master'

Fix Geo transfers failure handling when filename too long

Closes #3682

See merge request gitlab-org/gitlab-ee!3095
parents 8011b689 a3048ec8
......@@ -70,7 +70,7 @@ module Gitlab
temp_file.flush
unless response.success?
log_error("Unsuccessful download", response_code: response.code, response_msg: response.msg)
log_error("Unsuccessful download", filename: filename, response_code: response.code, response_msg: response.msg)
return file_size
end
......@@ -84,7 +84,7 @@ module Gitlab
file_size = File.stat(filename).size
log_info("Successful downloaded", filename: filename, file_size_bytes: file_size)
rescue StandardError, HTTParty::Error => e
log_error("Error downloading file", error: e)
log_error("Error downloading file", error: e, filename: filename)
ensure
temp_file.close
temp_file.unlink
......@@ -101,12 +101,13 @@ module Gitlab
begin
# Make sure the file is in the same directory to prevent moves across filesystems
pathname = Pathname.new(target_filename)
temp = Tempfile.new(TEMP_PREFIX + pathname.basename.to_s, pathname.dirname.to_s)
temp = Tempfile.new(TEMP_PREFIX, pathname.dirname.to_s)
temp.chmod(default_permissions)
temp.binmode
temp
rescue StandardError => e
log_error("Error creating temporary file", error: e)
nil
end
end
end
......
......@@ -47,5 +47,11 @@ describe Gitlab::Geo::Transfer do
expect(subject.download_from_primary).to eq(-1)
end
it 'when Tempfile fails' do
expect(Tempfile).to receive(:new).and_raise(Errno::ENAMETOOLONG)
expect(subject.download_from_primary).to eq(nil)
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