Class: Gitlab::Cleanup::ProjectUploads::ProjectUploadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/cleanup/project_uploads.rb

Constant Summary collapse

PROJECT_FULL_PATH_REGEX =
%r{\A#{FileUploader.root}/(.+)/(\h+/[^/]+)\z}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_path, upload_path) ⇒ ProjectUploadPath

Returns a new instance of ProjectUploadPath.


100
101
102
103
# File 'lib/gitlab/cleanup/project_uploads.rb', line 100

def initialize(full_path, upload_path)
  @full_path = full_path
  @upload_path = upload_path
end

Instance Attribute Details

#full_pathObject (readonly)

Returns the value of attribute full_path


98
99
100
# File 'lib/gitlab/cleanup/project_uploads.rb', line 98

def full_path
  @full_path
end

#upload_pathObject (readonly)

Returns the value of attribute upload_path


98
99
100
# File 'lib/gitlab/cleanup/project_uploads.rb', line 98

def upload_path
  @upload_path
end

Class Method Details

.from_path(path) ⇒ Object


105
106
107
108
109
110
# File 'lib/gitlab/cleanup/project_uploads.rb', line 105

def self.from_path(path)
  path_matched = path.match(PROJECT_FULL_PATH_REGEX)
  return new(nil, nil) unless path_matched

  new(path_matched[1], path_matched[2])
end

Instance Method Details

#orphan?Boolean

rubocop: disable CodeReuse/ActiveRecord

Returns:

  • (Boolean)

113
114
115
116
117
118
# File 'lib/gitlab/cleanup/project_uploads.rb', line 113

def orphan?
  return true if full_path.nil? || upload_path.nil?

  # It's possible to reduce to one query, but `where_full_path_in` is complex
  !Upload.exists?(path: upload_path, model_id: project_id, model_type: 'Project', uploader: 'FileUploader')
end