summaryrefslogtreecommitdiff
path: root/app/services/ci
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-02-24 02:40:41 +0900
committerShinya Maeda <shinya@gitlab.com>2018-02-24 02:40:41 +0900
commit8a56c5a1ac744a29a589c5a2ee1f26929f74105d (patch)
tree5727495f37e85df1946c2792f3492753e43d68aa /app/services/ci
parent34e16110e0fbe29c40fe984d4715ca5dcdaef508 (diff)
downloadgitlab-ce-8a56c5a1ac744a29a589c5a2ee1f26929f74105d.tar.gz
Revert "Revert "Use Dir.mktmpdir""
This reverts commit 34e16110e0fbe29c40fe984d4715ca5dcdaef508.
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/create_trace_artifact_service.rb29
1 files changed, 14 insertions, 15 deletions
diff --git a/app/services/ci/create_trace_artifact_service.rb b/app/services/ci/create_trace_artifact_service.rb
index dae741a371c..ffde824972c 100644
--- a/app/services/ci/create_trace_artifact_service.rb
+++ b/app/services/ci/create_trace_artifact_service.rb
@@ -6,9 +6,8 @@ module Ci
job.trace.read do |stream|
break unless stream.file?
- temp_file!(JobArtifactUploader.workhorse_upload_path) do |temp_path|
- FileUtils.copy(stream.path, temp_path)
- create_job_trace!(job, temp_path)
+ clone_file!(stream.path, JobArtifactUploader.workhorse_upload_path) do |clone_path|
+ create_job_trace!(job, clone_path)
FileUtils.rm(stream.path)
end
end
@@ -17,21 +16,21 @@ module Ci
private
def create_job_trace!(job, path)
- job.create_job_artifacts_trace!(
- project: job.project,
- file_type: :trace,
- file: UploadedFile.new(path, 'job.log', 'application/octet-stream')
- )
+ File.open(path) do |stream|
+ job.create_job_artifacts_trace!(
+ project: job.project,
+ file_type: :trace,
+ file: stream)
+ end
end
- def temp_file!(temp_dir)
+ def clone_file!(src_path, temp_dir)
FileUtils.mkdir_p(temp_dir)
- temp_file = Tempfile.new('trace-tmp-', temp_dir)
- temp_file&.close
- yield(temp_file.path)
- ensure
- temp_file&.close
- temp_file&.unlink
+ 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
end
end
end