2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
class Packages::PackageFile < ApplicationRecord
|
|
|
|
include UpdateProjectStatistics
|
2021-02-22 17:27:13 +05:30
|
|
|
include FileStoreMounter
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
delegate :project, :project_id, to: :package
|
|
|
|
delegate :conan_file_type, to: :conan_file_metadatum
|
2021-06-08 01:23:25 +05:30
|
|
|
delegate :file_type, :component, :architecture, :fields, to: :debian_file_metadatum, prefix: :debian
|
|
|
|
delegate :channel, :metadata, to: :helm_file_metadatum, prefix: :helm
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
belongs_to :package
|
|
|
|
|
|
|
|
has_one :conan_file_metadatum, inverse_of: :package_file, class_name: 'Packages::Conan::FileMetadatum'
|
2021-01-29 00:20:46 +05:30
|
|
|
has_many :package_file_build_infos, inverse_of: :package_file, class_name: 'Packages::PackageFileBuildInfo'
|
|
|
|
has_many :pipelines, through: :package_file_build_infos
|
2021-03-08 18:12:59 +05:30
|
|
|
has_one :debian_file_metadatum, inverse_of: :package_file, class_name: 'Packages::Debian::FileMetadatum'
|
2021-06-08 01:23:25 +05:30
|
|
|
has_one :helm_file_metadatum, inverse_of: :package_file, class_name: 'Packages::Helm::FileMetadatum'
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
accepts_nested_attributes_for :conan_file_metadatum
|
2021-03-08 18:12:59 +05:30
|
|
|
accepts_nested_attributes_for :debian_file_metadatum
|
2021-06-08 01:23:25 +05:30
|
|
|
accepts_nested_attributes_for :helm_file_metadatum
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
validates :package, presence: true
|
|
|
|
validates :file, presence: true
|
|
|
|
validates :file_name, presence: true
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
validates :file_name, uniqueness: { scope: :package }, if: -> { package&.pypi? }
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
scope :recent, -> { order(id: :desc) }
|
2021-06-08 01:23:25 +05:30
|
|
|
scope :for_package_ids, ->(ids) { where(package_id: ids) }
|
2020-07-28 23:09:34 +05:30
|
|
|
scope :with_file_name, ->(file_name) { where(file_name: file_name) }
|
|
|
|
scope :with_file_name_like, ->(file_name) { where(arel_table[:file_name].matches(file_name)) }
|
|
|
|
scope :with_files_stored_locally, -> { where(file_store: ::Packages::PackageFileUploader::Store::LOCAL) }
|
|
|
|
scope :preload_conan_file_metadata, -> { preload(:conan_file_metadatum) }
|
2021-03-08 18:12:59 +05:30
|
|
|
scope :preload_debian_file_metadata, -> { preload(:debian_file_metadatum) }
|
2021-09-04 01:27:46 +05:30
|
|
|
scope :preload_helm_file_metadata, -> { preload(:helm_file_metadatum) }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
scope :for_rubygem_with_file_name, ->(project, file_name) do
|
|
|
|
joins(:package).merge(project.packages.rubygems).with_file_name(file_name)
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
scope :for_helm_with_channel, ->(project, channel) do
|
|
|
|
joins(:package).merge(project.packages.helm.installable)
|
|
|
|
.joins(:helm_file_metadatum)
|
|
|
|
.where(packages_helm_file_metadata: { channel: channel })
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
scope :with_conan_file_type, ->(file_type) do
|
|
|
|
joins(:conan_file_metadatum)
|
|
|
|
.where(packages_conan_file_metadata: { conan_file_type: ::Packages::Conan::FileMetadatum.conan_file_types[file_type] })
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
scope :with_debian_file_type, ->(file_type) do
|
|
|
|
joins(:debian_file_metadatum)
|
2021-06-08 01:23:25 +05:30
|
|
|
.where(packages_debian_file_metadata: { file_type: ::Packages::Debian::FileMetadatum.file_types[file_type] })
|
|
|
|
end
|
|
|
|
|
|
|
|
scope :with_debian_component_name, ->(component_name) do
|
|
|
|
joins(:debian_file_metadatum)
|
|
|
|
.where(packages_debian_file_metadata: { component: component_name })
|
|
|
|
end
|
|
|
|
|
|
|
|
scope :with_debian_architecture_name, ->(architecture_name) do
|
|
|
|
joins(:debian_file_metadatum)
|
|
|
|
.where(packages_debian_file_metadata: { architecture: architecture_name })
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
scope :with_conan_package_reference, ->(conan_package_reference) do
|
|
|
|
joins(:conan_file_metadatum)
|
|
|
|
.where(packages_conan_file_metadata: { conan_package_reference: conan_package_reference })
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
mount_file_store_uploader Packages::PackageFileUploader
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
update_project_statistics project_statistics_name: :packages_size
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
before_save :update_size_from_file
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def download_path
|
2020-10-24 23:57:45 +05:30
|
|
|
Gitlab::Routing.url_helpers.download_project_package_file_path(project, self)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def update_size_from_file
|
|
|
|
self.size ||= file.size
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Packages::PackageFile.prepend_mod_with('Packages::PackageFile')
|