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
7a256b19
Commit
7a256b19
authored
Apr 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move checksum calculation to Upload.hexdigest
parent
39374921
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
7 deletions
+35
-7
app/models/upload.rb
app/models/upload.rb
+12
-2
lib/gitlab/geo/file_uploader.rb
lib/gitlab/geo/file_uploader.rb
+1
-5
spec/models/upload_spec.rb
spec/models/upload_spec.rb
+22
-0
No files found.
app/models/upload.rb
View file @
7a256b19
...
...
@@ -27,6 +27,16 @@ class Upload < ActiveRecord::Base
)
end
def
self
.
hexdigest
(
absolute_path
)
return
unless
exist?
(
absolute_path
)
Digest
::
SHA256
.
file
(
absolute_path
).
hexdigest
end
def
self
.
exist?
(
absolute_path
)
File
.
exist?
(
absolute_path
)
end
def
absolute_path
return
path
unless
relative_path?
...
...
@@ -36,11 +46,11 @@ class Upload < ActiveRecord::Base
def
calculate_checksum
return
unless
exist?
self
.
checksum
=
Digest
::
SHA256
.
file
(
absolute_path
).
hexdigest
self
.
checksum
=
self
.
class
.
hexdigest
(
absolute_path
)
end
def
exist?
File
.
exist?
(
absolute_path
)
self
.
class
.
exist?
(
absolute_path
)
end
private
...
...
lib/gitlab/geo/file_uploader.rb
View file @
7a256b19
...
...
@@ -30,11 +30,7 @@ module Gitlab
end
def
matches_checksum?
(
recorded_file
)
message
[
:checksum
]
==
calculate_checksum
(
recorded_file
.
absolute_path
)
end
def
calculate_checksum
(
absolute_path
)
Digest
::
SHA256
.
file
(
absolute_path
).
hexdigest
message
[
:checksum
]
==
Upload
.
hexdigest
(
recorded_file
.
absolute_path
)
end
def
success
(
file
)
...
...
spec/models/upload_spec.rb
View file @
7a256b19
...
...
@@ -90,6 +90,28 @@ describe Upload, type: :model do
end
end
describe
'.hexdigest'
do
it
'calculates the SHA256 sum'
do
expected
=
Digest
::
SHA256
.
file
(
__FILE__
).
hexdigest
expect
(
described_class
.
hexdigest
(
__FILE__
)).
to
eq
expected
end
it
'returns nil for a non-existant file'
do
expect
(
described_class
.
hexdigest
(
"
#{
__FILE__
}
-nope"
)).
to
be_nil
end
end
describe
'.exist?'
do
it
'returns true when the file exists'
do
expect
(
described_class
.
exist?
(
__FILE__
)).
to
eq
true
end
it
'returns false when the file does not exist'
do
expect
(
described_class
.
exist?
(
"
#{
__FILE__
}
-nope"
)).
to
eq
false
end
end
describe
'#absolute_path'
do
it
'returns the path directly when already absolute'
do
path
=
'/path/to/namespace/project/secret/file.jpg'
...
...
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