diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-02-23 20:35:03 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-02-23 20:35:03 +0300 |
commit | 34e16110e0fbe29c40fe984d4715ca5dcdaef508 (patch) | |
tree | 0519a18e6361da2e4ca682898d3a077b9034e57f /app/services | |
parent | 28c6a6b04436230e6e9b29855e4d4d4f88d9a554 (diff) |
Revert "Use Dir.mktmpdir"
This reverts commit 28c6a6b04436230e6e9b29855e4d4d4f88d9a554.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/ci/create_trace_artifact_service.rb | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/app/services/ci/create_trace_artifact_service.rb b/app/services/ci/create_trace_artifact_service.rb index ffde824972c..dae741a371c 100644 --- a/app/services/ci/create_trace_artifact_service.rb +++ b/app/services/ci/create_trace_artifact_service.rb @@ -6,8 +6,9 @@ module Ci job.trace.read do |stream| break unless stream.file? - clone_file!(stream.path, JobArtifactUploader.workhorse_upload_path) do |clone_path| - create_job_trace!(job, clone_path) + temp_file!(JobArtifactUploader.workhorse_upload_path) do |temp_path| + FileUtils.copy(stream.path, temp_path) + create_job_trace!(job, temp_path) FileUtils.rm(stream.path) end end @@ -16,21 +17,21 @@ module Ci private def create_job_trace!(job, path) - File.open(path) do |stream| - job.create_job_artifacts_trace!( - project: job.project, - file_type: :trace, - file: stream) - end + job.create_job_artifacts_trace!( + project: job.project, + file_type: :trace, + file: UploadedFile.new(path, 'job.log', 'application/octet-stream') + ) end - def clone_file!(src_path, temp_dir) + def temp_file!(temp_dir) FileUtils.mkdir_p(temp_dir) - Dir.mktmpdir('tmp-trace', temp_dir) do |dir_path| - temp_path = File.join(dir_path, "job.log") - FileUtils.copy(src_path, temp_path) - yield(temp_path) - end + temp_file = Tempfile.new('trace-tmp-', temp_dir) + temp_file&.close + yield(temp_file.path) + ensure + temp_file&.close + temp_file&.unlink end end end |