summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2018-05-29 13:48:23 +0200
committerAlessio Caiazza <acaiazza@gitlab.com>2019-07-02 10:56:49 +0200
commitcf60bdb65268233b85f568799e04f67d1bac4342 (patch)
tree4a0dc507f70ab8ae875e97af93ef4293c419a096
parent10a3ef2254dfc2ea5bce073df3ad366eef82d84d (diff)
downloadgitlab-ce-fix-only-os-uplods.tar.gz
Disable local copy of files with direct_uploadfix-only-os-uplods
When workhorse writes files directly to object storage, there's no need to also write it on disk
-rw-r--r--app/uploaders/object_storage.rb1
-rw-r--r--lib/uploaded_file.rb30
2 files changed, 23 insertions, 8 deletions
diff --git a/app/uploaders/object_storage.rb b/app/uploaders/object_storage.rb
index 0a44d60778d..800a7e5cbb7 100644
--- a/app/uploaders/object_storage.rb
+++ b/app/uploaders/object_storage.rb
@@ -185,6 +185,7 @@ module ObjectStorage
end
def workhorse_local_upload_path
+ return if self.object_store_enabled? && self.direct_upload_enabled?
File.join(self.root, TMP_UPLOAD_PATH)
end
diff --git a/lib/uploaded_file.rb b/lib/uploaded_file.rb
index aae542f02ac..cfd866f97ab 100644
--- a/lib/uploaded_file.rb
+++ b/lib/uploaded_file.rb
@@ -18,16 +18,23 @@ class UploadedFile
attr_reader :remote_id
attr_reader :sha256
+ attr_reader :size
- def initialize(path, filename: nil, content_type: "application/octet-stream", sha256: nil, remote_id: nil)
- raise InvalidPathError, "#{path} file does not exist" unless ::File.exist?(path)
+ def initialize(path, filename: nil, content_type: "application/octet-stream", sha256: nil, remote_id: nil, size: nil)
+ if remote_id.blank?
+ raise InvalidPathError, "#{path} file does not exist" unless ::File.exist?(path)
+
+ @tempfile = File.new(path, 'rb')
+ @size = @tempfile.size
+ else
+ @size = size
+ end
@content_type = content_type
@original_filename = sanitize_filename(filename || path)
@content_type = content_type
@sha256 = sha256
@remote_id = remote_id
- @tempfile = File.new(path, 'rb')
end
def self.from_params(params, field, upload_paths)
@@ -37,18 +44,25 @@ class UploadedFile
return
end
- file_path = File.realpath(params["#{field}.path"])
+ file_path = nil
+
+ if params["#{field}.path"]
+ file_path = File.realpath(params["#{field}.path"])
- paths = Array(upload_paths) << Dir.tmpdir
- unless self.allowed_path?(file_path, paths.compact)
- raise InvalidPathError, "insecure path used '#{file_path}'"
+ paths = Array(upload_paths) << Dir.tmpdir
+ unless self.allowed_path?(file_path, paths.compact)
+ raise InvalidPathError, "insecure path used '#{file_path}'"
+ end
+ else
+ raise InvalidPathError, "file is invalid" if params["#{field}.remote_id"].blank?
end
UploadedFile.new(file_path,
filename: params["#{field}.name"],
content_type: params["#{field}.type"] || 'application/octet-stream',
sha256: params["#{field}.sha256"],
- remote_id: params["#{field}.remote_id"])
+ remote_id: params["#{field}.remote_id"],
+ size: params["#{field}.size"])
end
def self.allowed_path?(file_path, paths)