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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
869d08b5
Commit
869d08b5
authored
Dec 05, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Process normal paths in batch containing bad paths
parent
77be7efc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
4 deletions
+45
-4
lib/gitlab/background_migration/populate_untracked_uploads.rb
...gitlab/background_migration/populate_untracked_uploads.rb
+25
-4
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
...b/background_migration/populate_untracked_uploads_spec.rb
+20
-0
No files found.
lib/gitlab/background_migration/populate_untracked_uploads.rb
View file @
869d08b5
...
...
@@ -57,7 +57,7 @@ module Gitlab
].
freeze
def
to_h
{
@upload_hash
||=
{
path:
upload_path
,
uploader:
uploader
,
model_type:
model_type
,
...
...
@@ -156,8 +156,8 @@ module Gitlab
return
unless
migrate?
files
=
UntrackedFile
.
where
(
id:
start_id
..
end_id
)
insert_uploads_if_needed
(
files
)
files
.
delete_all
processed_files
=
insert_uploads_if_needed
(
files
)
processed_
files
.
delete_all
drop_temp_table_if_finished
end
...
...
@@ -169,9 +169,30 @@ module Gitlab
end
def
insert_uploads_if_needed
(
files
)
filtered_files
=
filter_existing_uploads
(
files
)
filtered_files
,
error_files
=
filter_error_files
(
files
)
filtered_files
=
filter_existing_uploads
(
filtered_files
)
filtered_files
=
filter_deleted_models
(
filtered_files
)
insert
(
filtered_files
)
processed_files
=
files
.
where
.
not
(
id:
error_files
.
map
(
&
:id
))
processed_files
end
def
filter_error_files
(
files
)
files
.
partition
do
|
file
|
begin
file
.
to_h
true
rescue
=>
e
msg
=
<<~
MSG
Error parsing path "
#{
file
.
path
}
":
#{
e
.
message
}
#{
e
.
backtrace
.
join
(
"
\n
"
)
}
MSG
Rails
.
logger
.
error
(
msg
)
false
end
end
end
def
filter_existing_uploads
(
files
)
...
...
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
View file @
869d08b5
...
...
@@ -119,6 +119,26 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
expect
(
table_exists?
(
:untracked_files_for_uploads
)).
to
be_falsey
end
it
'does not block a whole batch because of one bad path'
do
untracked_files_for_uploads
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrackedUploads
::
RELATIVE_UPLOAD_DIR
}
/
#{
project2
.
full_path
}
/._7d37bf4c747916390e596744117d5d1a"
)
expect
(
untracked_files_for_uploads
.
count
).
to
eq
(
9
)
expect
(
uploads
.
count
).
to
eq
(
4
)
subject
.
perform
(
1
,
untracked_files_for_uploads
.
last
.
id
)
expect
(
untracked_files_for_uploads
.
count
).
to
eq
(
1
)
expect
(
uploads
.
count
).
to
eq
(
8
)
end
it
'an unparseable path is shown in error output'
do
bad_path
=
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrackedUploads
::
RELATIVE_UPLOAD_DIR
}
/
#{
project2
.
full_path
}
/._7d37bf4c747916390e596744117d5d1a"
untracked_files_for_uploads
.
create!
(
path:
bad_path
)
expect
(
Rails
.
logger
).
to
receive
(
:error
).
with
(
/Error parsing path "
#{
bad_path
}
":/
)
subject
.
perform
(
1
,
untracked_files_for_uploads
.
last
.
id
)
end
end
context
'with no untracked files'
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