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 ...@@ -70,7 +70,7 @@ module Gitlab
temp_file.flush temp_file.flush
unless response.success? 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 return file_size
end end
...@@ -84,7 +84,7 @@ module Gitlab ...@@ -84,7 +84,7 @@ module Gitlab
file_size = File.stat(filename).size file_size = File.stat(filename).size
log_info("Successful downloaded", filename: filename, file_size_bytes: file_size) log_info("Successful downloaded", filename: filename, file_size_bytes: file_size)
rescue StandardError, HTTParty::Error => e rescue StandardError, HTTParty::Error => e
log_error("Error downloading file", error: e) log_error("Error downloading file", error: e, filename: filename)
ensure ensure
temp_file.close temp_file.close
temp_file.unlink temp_file.unlink
...@@ -101,12 +101,13 @@ module Gitlab ...@@ -101,12 +101,13 @@ module Gitlab
begin begin
# Make sure the file is in the same directory to prevent moves across filesystems # Make sure the file is in the same directory to prevent moves across filesystems
pathname = Pathname.new(target_filename) 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.chmod(default_permissions)
temp.binmode temp.binmode
temp temp
rescue StandardError => e rescue StandardError => e
log_error("Error creating temporary file", error: e) log_error("Error creating temporary file", error: e)
nil
end end
end end
end end
......
...@@ -47,5 +47,11 @@ describe Gitlab::Geo::Transfer do ...@@ -47,5 +47,11 @@ describe Gitlab::Geo::Transfer do
expect(subject.download_from_primary).to eq(-1) expect(subject.download_from_primary).to eq(-1)
end 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
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