summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/command_line_util.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-07 06:15:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-07 06:15:33 +0000
commit0ead22f9db870eb1d6914ef60d5c1c998ed538d9 (patch)
tree42cc4f297aa116bc517c86c943428ef0840b70ef /lib/gitlab/import_export/command_line_util.rb
parent9d20ce8c998506a1e27c55bbf99cd4c0595185af (diff)
downloadgitlab-ce-0ead22f9db870eb1d6914ef60d5c1c998ed538d9.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/import_export/command_line_util.rb')
-rw-r--r--lib/gitlab/import_export/command_line_util.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb
index e520cade517..68d0494fbe2 100644
--- a/lib/gitlab/import_export/command_line_util.rb
+++ b/lib/gitlab/import_export/command_line_util.rb
@@ -6,6 +6,8 @@ module Gitlab
UNTAR_MASK = 'u+rwX,go+rX,go-w'
DEFAULT_DIR_MODE = 0700
+ FileOversizedError = Class.new(StandardError)
+
def tar_czf(archive:, dir:)
tar_with_options(archive: archive, dir: dir, options: 'czf')
end
@@ -51,19 +53,30 @@ module Gitlab
private
- def download_or_copy_upload(uploader, upload_path)
+ def download_or_copy_upload(uploader, upload_path, size_limit: nil)
if uploader.upload.local?
copy_files(uploader.path, upload_path)
else
- download(uploader.url, upload_path)
+ download(uploader.url, upload_path, size_limit: size_limit)
end
end
- def download(url, upload_path)
+ def download(url, upload_path, size_limit: nil)
File.open(upload_path, 'w') do |file|
# Download (stream) file from the uploader's location
- IO.copy_stream(URI.parse(url).open, file)
+ IO.copy_stream(
+ URI.parse(url).open(progress_proc: file_size_limiter(size_limit)),
+ file
+ )
end
+ rescue FileOversizedError
+ nil
+ end
+
+ def file_size_limiter(limit)
+ return if limit.blank?
+
+ -> (current_size) { raise FileOversizedError if current_size > limit }
end
def tar_with_options(archive:, dir:, options:)