diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-09-02 14:31:46 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-09-02 14:31:46 +0000 |
commit | ece30b70ca3545e396963974aa0f27f37512bf97 (patch) | |
tree | 5ba2485156bfbf403a8118bade9fd663f74ea4e9 /app | |
parent | 4d07696aabac5fe920b9358816a4776b3fddb43a (diff) | |
parent | 52fe6098861bf36601be6555d2b39f366795ddd3 (diff) | |
download | gitlab-ce-ece30b70ca3545e396963974aa0f27f37512bf97.tar.gz |
Merge branch 'fix/handle-raw-trace-error-on-old-builds' into 'master'
Handle error on trace raw download with old builds (DB stored)
## What does this MR do?
Handles error on `raw build trace` download action for old builds (which are stored in DB instead of file).
## Are there points in the code the reviewer needs to double check?
No.
## Why was this MR needed?
At the beginning build traces were stored in database but at some point we moved to store them in files. All trace related actions are aware of this, but not `raw trace download`.
## What are the relevant issue numbers?
Fixes #18900
## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [ ] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- [ ] ~~API support added~~
- Tests
- [x] Added for this feature/bug
- [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
See merge request !4822
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/builds_controller.rb | 4 | ||||
-rw-r--r-- | app/models/ci/build.rb | 27 | ||||
-rw-r--r-- | app/views/projects/builds/_sidebar.html.haml | 2 |
3 files changed, 25 insertions, 8 deletions
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index 12195c3cbb8..77934ff9962 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -78,8 +78,8 @@ class Projects::BuildsController < Projects::ApplicationController end def raw - if @build.has_trace? - send_file @build.path_to_trace, type: 'text/plain; charset=utf-8', disposition: 'inline' + if @build.has_trace_file? + send_file @build.trace_file_path, type: 'text/plain; charset=utf-8', disposition: 'inline' else render_404 end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 23c8de6f650..61052437318 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -208,22 +208,31 @@ module Ci end end + def has_trace_file? + File.exist?(path_to_trace) || has_old_trace_file? + end + def has_trace? raw_trace.present? end def raw_trace - if File.file?(path_to_trace) - File.read(path_to_trace) - elsif project.ci_id && File.file?(old_path_to_trace) - # Temporary fix for build trace data integrity - File.read(old_path_to_trace) + if File.exist?(trace_file_path) + File.read(trace_file_path) else # backward compatibility read_attribute :trace end end + ## + # Deprecated + # + # This is a hotfix for CI build data integrity, see #4246 + def has_old_trace_file? + project.ci_id && File.exist?(old_path_to_trace) + end + def trace trace = raw_trace if project && trace.present? && project.runners_token.present? @@ -262,6 +271,14 @@ module Ci end end + def trace_file_path + if has_old_trace_file? + old_path_to_trace + else + path_to_trace + end + end + def dir_to_trace File.join( Settings.gitlab_ci.builds_path, diff --git a/app/views/projects/builds/_sidebar.html.haml b/app/views/projects/builds/_sidebar.html.haml index 5b0b58e087b..49c8bd11634 100644 --- a/app/views/projects/builds/_sidebar.html.haml +++ b/app/views/projects/builds/_sidebar.html.haml @@ -100,7 +100,7 @@ - elsif @build.runner \##{@build.runner.id} .btn-group.btn-group-justified{ role: :group } - - if @build.has_trace? + - if @build.has_trace_file? = link_to 'Raw', raw_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-default' - if @build.active? = link_to "Cancel", cancel_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-default', method: :post |