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
6da944d3
Commit
6da944d3
authored
Oct 08, 2019
by
Brian Kabiro
Committed by
Michael Kozono
Oct 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Checksummable concern
- create the checksummable concern file
parent
5c6b1b47
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
55 additions
and
10 deletions
+55
-10
app/models/concerns/checksummable.rb
app/models/concerns/checksummable.rb
+11
-0
app/models/lfs_object.rb
app/models/lfs_object.rb
+2
-1
app/models/upload.rb
app/models/upload.rb
+2
-5
changelogs/unreleased/12764-refactor-checksum-code.yml
changelogs/unreleased/12764-refactor-checksum-code.yml
+5
-0
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+2
-1
spec/models/concerns/checksummable_spec.rb
spec/models/concerns/checksummable_spec.rb
+19
-0
spec/models/lfs_object_spec.rb
spec/models/lfs_object_spec.rb
+11
-0
spec/support/shared_examples/ci_trace_shared_examples.rb
spec/support/shared_examples/ci_trace_shared_examples.rb
+3
-3
No files found.
app/models/concerns/checksummable.rb
0 → 100644
View file @
6da944d3
# frozen_string_literal: true
module
Checksummable
extend
ActiveSupport
::
Concern
class_methods
do
def
hexdigest
(
path
)
Digest
::
SHA256
.
file
(
path
).
hexdigest
end
end
end
app/models/lfs_object.rb
View file @
6da944d3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
class
LfsObject
<
ApplicationRecord
class
LfsObject
<
ApplicationRecord
include
AfterCommitQueue
include
AfterCommitQueue
include
Checksummable
include
EachBatch
include
EachBatch
include
ObjectStorage
::
BackgroundMove
include
ObjectStorage
::
BackgroundMove
...
@@ -46,7 +47,7 @@ class LfsObject < ApplicationRecord
...
@@ -46,7 +47,7 @@ class LfsObject < ApplicationRecord
# rubocop: enable DestroyAll
# rubocop: enable DestroyAll
def
self
.
calculate_oid
(
path
)
def
self
.
calculate_oid
(
path
)
Digest
::
SHA256
.
file
(
path
).
hexdigest
self
.
hexdigest
(
path
)
end
end
end
end
...
...
app/models/upload.rb
View file @
6da944d3
# frozen_string_literal: true
# frozen_string_literal: true
class
Upload
<
ApplicationRecord
class
Upload
<
ApplicationRecord
include
Checksummable
# Upper limit for foreground checksum processing
# Upper limit for foreground checksum processing
CHECKSUM_THRESHOLD
=
100
.
megabytes
CHECKSUM_THRESHOLD
=
100
.
megabytes
...
@@ -21,10 +22,6 @@ class Upload < ApplicationRecord
...
@@ -21,10 +22,6 @@ class Upload < ApplicationRecord
# hooks are not executed and the file will not be deleted
# hooks are not executed and the file will not be deleted
after_destroy
:delete_file!
,
if:
->
{
uploader_class
<=
FileUploader
}
after_destroy
:delete_file!
,
if:
->
{
uploader_class
<=
FileUploader
}
def
self
.
hexdigest
(
path
)
Digest
::
SHA256
.
file
(
path
).
hexdigest
end
class
<<
self
class
<<
self
##
##
# FastDestroyAll concerns
# FastDestroyAll concerns
...
@@ -55,7 +52,7 @@ class Upload < ApplicationRecord
...
@@ -55,7 +52,7 @@ class Upload < ApplicationRecord
self
.
checksum
=
nil
self
.
checksum
=
nil
return
unless
needs_checksum?
return
unless
needs_checksum?
self
.
checksum
=
Digest
::
SHA256
.
file
(
absolute_path
).
hexdigest
self
.
checksum
=
self
.
class
.
hexdigest
(
absolute_path
)
end
end
# Initialize the associated Uploader class with current model
# Initialize the associated Uploader class with current model
...
...
changelogs/unreleased/12764-refactor-checksum-code.yml
0 → 100644
View file @
6da944d3
---
title
:
Refactor checksum code in uploads
merge_request
:
18065
author
:
briankabiro
type
:
other
lib/gitlab/ci/trace.rb
View file @
6da944d3
...
@@ -4,6 +4,7 @@ module Gitlab
...
@@ -4,6 +4,7 @@ module Gitlab
module
Ci
module
Ci
class
Trace
class
Trace
include
::
Gitlab
::
ExclusiveLeaseHelpers
include
::
Gitlab
::
ExclusiveLeaseHelpers
include
Checksummable
LOCK_TTL
=
10
.
minutes
LOCK_TTL
=
10
.
minutes
LOCK_RETRIES
=
2
LOCK_RETRIES
=
2
...
@@ -193,7 +194,7 @@ module Gitlab
...
@@ -193,7 +194,7 @@ module Gitlab
project:
job
.
project
,
project:
job
.
project
,
file_type: :trace
,
file_type: :trace
,
file:
stream
,
file:
stream
,
file_sha256:
Digest
::
SHA256
.
file
(
path
).
hexdigest
)
file_sha256:
self
.
class
.
hexdigest
(
path
)
)
end
end
end
end
...
...
spec/models/concerns/checksummable_spec.rb
0 → 100644
View file @
6da944d3
# frozen_string_literal: true
require
'spec_helper'
describe
Checksummable
do
describe
".hexdigest"
do
let
(
:fake_class
)
do
Class
.
new
do
include
Checksummable
end
end
it
'returns the SHA256 sum of the file'
do
expected
=
Digest
::
SHA256
.
file
(
__FILE__
).
hexdigest
expect
(
fake_class
.
hexdigest
(
__FILE__
)).
to
eq
(
expected
)
end
end
end
spec/models/lfs_object_spec.rb
View file @
6da944d3
...
@@ -156,4 +156,15 @@ describe LfsObject do
...
@@ -156,4 +156,15 @@ describe LfsObject do
end
end
end
end
end
end
describe
".calculate_oid"
do
let
(
:lfs_object
)
{
create
(
:lfs_object
,
:with_file
)
}
it
'returns SHA256 sum of the file'
do
path
=
lfs_object
.
file
.
path
expected
=
Digest
::
SHA256
.
file
(
path
).
hexdigest
expect
(
described_class
.
calculate_oid
(
path
)).
to
eq
expected
end
end
end
end
spec/support/shared_examples/ci_trace_shared_examples.rb
View file @
6da944d3
...
@@ -423,7 +423,7 @@ shared_examples_for 'trace with disabled live trace feature' do
...
@@ -423,7 +423,7 @@ shared_examples_for 'trace with disabled live trace feature' do
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
File
.
exist?
(
src_path
)).
to
be_falsy
expect
(
File
.
exist?
(
src_path
)).
to
be_falsy
expect
(
src_checksum
)
expect
(
src_checksum
)
.
to
eq
(
Digest
::
SHA256
.
file
(
build
.
job_artifacts_trace
.
file
.
path
).
hexdigest
)
.
to
eq
(
described_class
.
hexdigest
(
build
.
job_artifacts_trace
.
file
.
path
)
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
end
end
end
end
...
@@ -449,7 +449,7 @@ shared_examples_for 'trace with disabled live trace feature' do
...
@@ -449,7 +449,7 @@ shared_examples_for 'trace with disabled live trace feature' do
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
build
.
old_trace
).
to
be_nil
expect
(
build
.
old_trace
).
to
be_nil
expect
(
src_checksum
)
expect
(
src_checksum
)
.
to
eq
(
Digest
::
SHA256
.
file
(
build
.
job_artifacts_trace
.
file
.
path
).
hexdigest
)
.
to
eq
(
described_class
.
hexdigest
(
build
.
job_artifacts_trace
.
file
.
path
)
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
end
end
end
end
...
@@ -787,7 +787,7 @@ shared_examples_for 'trace with enabled live trace feature' do
...
@@ -787,7 +787,7 @@ shared_examples_for 'trace with enabled live trace feature' do
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
build
.
job_artifacts_trace
.
file
.
filename
).
to
eq
(
'job.log'
)
expect
(
Ci
::
BuildTraceChunk
.
where
(
build:
build
)).
not_to
be_exist
expect
(
Ci
::
BuildTraceChunk
.
where
(
build:
build
)).
not_to
be_exist
expect
(
src_checksum
)
expect
(
src_checksum
)
.
to
eq
(
Digest
::
SHA256
.
file
(
build
.
job_artifacts_trace
.
file
.
path
).
hexdigest
)
.
to
eq
(
described_class
.
hexdigest
(
build
.
job_artifacts_trace
.
file
.
path
)
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
expect
(
build
.
job_artifacts_trace
.
file_sha256
).
to
eq
(
src_checksum
)
end
end
end
end
...
...
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