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
cc7f1297
Commit
cc7f1297
authored
Feb 05, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix CE to EE conflicts
parent
0b6dead2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
0 deletions
+54
-0
app/models/upload.rb
app/models/upload.rb
+8
-0
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+6
-0
changelogs/unreleased/14256-upload-destroy-removes-file.yml
changelogs/unreleased/14256-upload-destroy-removes-file.yml
+5
-0
spec/models/upload_spec.rb
spec/models/upload_spec.rb
+12
-0
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+23
-0
No files found.
app/models/upload.rb
View file @
cc7f1297
...
...
@@ -14,6 +14,10 @@ class Upload < ActiveRecord::Base
before_save
:calculate_checksum!
,
if: :foreground_checksummable?
after_commit
:schedule_checksum
,
if: :checksummable?
# as the FileUploader is not mounted, the default CarrierWave ActiveRecord
# hooks are not executed and the file will not be deleted
after_destroy
:delete_file!
,
if:
->
{
uploader_class
<=
FileUploader
}
def
self
.
hexdigest
(
path
)
Digest
::
SHA256
.
file
(
path
).
hexdigest
end
...
...
@@ -52,6 +56,10 @@ class Upload < ActiveRecord::Base
private
def
delete_file!
build_uploader
.
remove!
end
def
checksummable?
checksum
.
nil?
&&
local?
&&
exist?
end
...
...
app/uploaders/file_uploader.rb
View file @
cc7f1297
...
...
@@ -15,6 +15,8 @@ class FileUploader < GitlabUploader
MARKDOWN_PATTERN
=
%r{
\!
?
\[
.*?
\]\(
/uploads/(?<secret>[0-9a-f]{32})/(?<file>.*?)
\)
}
DYNAMIC_PATH_PATTERN
=
%r{(?<secret>
\h
{32})/(?<identifier>.*)}
after
:remove
,
:prune_store_dir
def
self
.
root
File
.
join
(
options
.
storage_path
,
'uploads'
)
end
...
...
@@ -140,6 +142,10 @@ class FileUploader < GitlabUploader
end
end
def
prune_store_dir
storage
.
delete_dir!
(
store_dir
)
# only remove when empty
end
def
markdown_name
(
image_or_video?
?
File
.
basename
(
filename
,
File
.
extname
(
filename
))
:
filename
).
gsub
(
"]"
,
"
\\
]"
)
end
...
...
changelogs/unreleased/14256-upload-destroy-removes-file.yml
0 → 100644
View file @
cc7f1297
---
title
:
Deleting an upload will correctly clean up the filesystem.
merge_request
:
16799
author
:
type
:
fixed
spec/models/upload_spec.rb
View file @
cc7f1297
...
...
@@ -43,6 +43,18 @@ describe Upload do
.
to
(
a_string_matching
(
/\A\h{64}\z/
))
end
end
describe
'after_destroy'
do
context
'uploader is FileUploader-based'
do
subject
{
create
(
:upload
,
:issuable_upload
)
}
it
'calls delete_file!'
do
is_expected
.
to
receive
(
:delete_file!
)
subject
.
destroy
end
end
end
end
describe
'#absolute_path'
do
...
...
spec/uploaders/file_uploader_spec.rb
View file @
cc7f1297
...
...
@@ -66,6 +66,29 @@ describe FileUploader do
end
end
describe
'callbacks'
do
describe
'#prune_store_dir after :remove'
do
before
do
uploader
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
def
store_dir
File
.
expand_path
(
uploader
.
store_dir
,
uploader
.
root
)
end
it
'is called'
do
expect
(
uploader
).
to
receive
(
:prune_store_dir
).
once
uploader
.
remove!
end
it
'prune the store directory'
do
expect
{
uploader
.
remove!
}
.
to
change
{
File
.
exist?
(
store_dir
)
}.
from
(
true
).
to
(
false
)
end
end
end
describe
"#migrate!"
do
before
do
uploader
.
store!
(
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/dk.png'
)))
...
...
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