Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
414a638b
Commit
414a638b
authored
Feb 23, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if the latest permanent file exists before remove file. Add tests.
parent
0fca3bce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
16 deletions
+31
-16
app/services/ci/create_trace_artifact_service.rb
app/services/ci/create_trace_artifact_service.rb
+13
-14
spec/services/ci/create_trace_artifact_service_spec.rb
spec/services/ci/create_trace_artifact_service_spec.rb
+18
-2
No files found.
app/services/ci/create_trace_artifact_service.rb
View file @
414a638b
...
@@ -6,28 +6,27 @@ module Ci
...
@@ -6,28 +6,27 @@ module Ci
job
.
trace
.
read
do
|
stream
|
job
.
trace
.
read
do
|
stream
|
return
unless
stream
.
file?
return
unless
stream
.
file?
temp_file!
(
JobArtifactUploader
.
workhorse_upload_path
)
do
|
temp_path
|
temp_file!
(
stream
.
path
,
JobArtifactUploader
.
workhorse_upload_path
)
do
|
temp_path
|
FileUtils
.
cp
(
stream
.
path
,
temp_path
)
create_job_trace!
(
job
,
temp_path
)
FileUtils
.
rm
(
stream
.
path
)
end
end
end
private
def
create_job_trace!
(
job
,
path
)
job
.
create_job_artifacts_trace!
(
job
.
create_job_artifacts_trace!
(
project:
job
.
project
,
project:
job
.
project
,
file_type: :trace
,
file_type: :trace
,
file:
UploadedFile
.
new
(
path
,
'job.log'
,
'application/octet-stream'
)
file:
UploadedFile
.
new
(
temp_
path
,
'job.log'
,
'application/octet-stream'
)
)
)
end
end
def
temp_file!
(
temp_dir
)
raise
'Trace artifact not found'
unless
job
.
job_artifacts_trace
.
file
.
exists?
FileUtils
.
rm
(
stream
.
path
)
end
end
private
def
temp_file!
(
src_file
,
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
temp_file
=
Tempfile
.
new
(
'
legacy-
trace-tmp-'
,
temp_dir
)
temp_file
=
Tempfile
.
new
(
'trace-tmp-'
,
temp_dir
)
temp_file
&
.
close
temp_file
&
.
close
FileUtils
.
cp
(
src_file
,
temp_file
.
path
)
yield
(
temp_file
.
path
)
yield
(
temp_file
.
path
)
ensure
ensure
temp_file
&
.
close
temp_file
&
.
close
...
...
spec/services/ci/create_trace_artifact_service_spec.rb
View file @
414a638b
...
@@ -8,6 +8,9 @@ describe Ci::CreateTraceArtifactService do
...
@@ -8,6 +8,9 @@ describe Ci::CreateTraceArtifactService do
context
'when the job has a trace file'
do
context
'when the job has a trace file'
do
let!
(
:job
)
{
create
(
:ci_build
,
:trace_live
)
}
let!
(
:job
)
{
create
(
:ci_build
,
:trace_live
)
}
let!
(
:legacy_path
)
{
job
.
trace
.
read
{
|
stream
|
return
stream
.
path
}
}
let!
(
:legacy_path
)
{
job
.
trace
.
read
{
|
stream
|
return
stream
.
path
}
}
let!
(
:legacy_checksum
)
{
Digest
::
SHA256
.
file
(
legacy_path
).
hexdigest
}
let
(
:new_path
)
{
job
.
job_artifacts_trace
.
file
.
path
}
let
(
:new_checksum
)
{
Digest
::
SHA256
.
file
(
new_path
).
hexdigest
}
it
{
expect
(
File
.
exists?
(
legacy_path
)).
to
be_truthy
}
it
{
expect
(
File
.
exists?
(
legacy_path
)).
to
be_truthy
}
...
@@ -15,8 +18,9 @@ describe Ci::CreateTraceArtifactService do
...
@@ -15,8 +18,9 @@ describe Ci::CreateTraceArtifactService do
expect
{
subject
}.
to
change
{
Ci
::
JobArtifact
.
count
}.
by
(
1
)
expect
{
subject
}.
to
change
{
Ci
::
JobArtifact
.
count
}.
by
(
1
)
expect
(
File
.
exists?
(
legacy_path
)).
to
be_falsy
expect
(
File
.
exists?
(
legacy_path
)).
to
be_falsy
expect
(
File
.
exists?
(
job
.
job_artifacts_trace
.
file
.
path
)).
to
be_truthy
expect
(
File
.
exists?
(
new_path
)).
to
be_truthy
expect
(
job
.
job_artifacts_trace
.
exists?
).
to
be_truthy
expect
(
new_checksum
).
to
eq
(
legacy_checksum
)
expect
(
job
.
job_artifacts_trace
.
file
.
exists?
).
to
be_truthy
expect
(
job
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
job
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
end
end
...
@@ -37,6 +41,18 @@ describe Ci::CreateTraceArtifactService do
...
@@ -37,6 +41,18 @@ describe Ci::CreateTraceArtifactService do
expect
(
job
.
job_artifacts_trace
).
to
be_nil
expect
(
job
.
job_artifacts_trace
).
to
be_nil
end
end
end
end
context
'when migrated trace artifact file is not found'
do
before
do
allow_any_instance_of
(
CarrierWave
::
SanitizedFile
).
to
receive
(
:exists?
)
{
false
}
end
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
'Trace artifact not found'
)
expect
(
File
.
exists?
(
legacy_path
)).
to
be_truthy
end
end
end
end
context
'when the job does not have a trace file'
do
context
'when the job does not have a trace file'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment