Class: Packages::Conan::CreatePackageFileService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/conan/create_package_file_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(package, file, params) ⇒ CreatePackageFileService

Returns a new instance of CreatePackageFileService.



8
9
10
11
12
# File 'app/services/packages/conan/create_package_file_service.rb', line 8

def initialize(package, file, params)
  @package = package
  @file = file
  @params = params
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/services/packages/conan/create_package_file_service.rb', line 14

def execute
  package_file = nil
  ApplicationRecord.transaction do
    package_file = package.package_files.build(
      file: file,
      size: params['file.size'],
      file_name: params[:file_name],
      file_sha1: params['file.sha1'],
      file_md5: params['file.md5'],
      project_id: package.project_id,
      conan_file_metadatum_attributes: {
        conan_file_type: params[:conan_file_type],
        package_reference_id: package_reference_id,
        recipe_revision_id: recipe_revision_id,
        package_revision_id: package_revision_id
      }
    )

    if params[:build].present?
      package_file.package_file_build_infos << package_file.package_file_build_infos.build(pipeline: params[:build].pipeline)
    end

    package_file.save!

    # Conan sorts the files before the upload and the last one is always "conanmanifest.txt"
    # https://github.com/conan-io/conan/blob/9826fbd57f43b847d22d4530dfe40f015f4dc9e5/conan/internal/rest/rest_client_v2.py#L303
    # Conan server updates the "latest" revision after "conanmanifest.txt" is uploaded:
    # https://github.com/conan-io/conan/blob/9826fbd57f43b847d22d4530dfe40f015f4dc9e5/conans/server/service/v2/service_v2.py#L47
    # https://github.com/conan-io/conan/blob/9826fbd57f43b847d22d4530dfe40f015f4dc9e5/conans/server/service/v2/service_v2.py#L110
    update_revision_status if package_file.file_name == ::Packages::Conan::FileMetadatum::MANIFEST_FILE
  end

  if package_file.file_name == ::Packages::Conan::FileMetadatum::CONANINFO_TXT
    ::Packages::Conan::ProcessPackageFileWorker.perform_async(package_file.id)
  end

  ServiceResponse.success(payload: { package_file: package_file })
rescue ActiveRecord::RecordInvalid => e
  ServiceResponse.error(message: e.message, reason: :invalid_package_file)
end