Welcome to mirror list, hosted at ThFree Co, Russian Federation.

extract_deb_metadata_service.rb « debian « packages « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb106f4cd308c7cde2c265314ff364c76b465864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
# frozen_string_literal: true

module Packages
  module Debian
    # Returns .deb file metadata
    class ExtractDebMetadataService
      CommandFailedError = Class.new(StandardError)

      def initialize(file_path)
        @file_path = file_path
      end

      def execute
        unless success?
          raise CommandFailedError, "The `#{cmd}` command failed (status: #{result.status}) with the following error:\n#{result.stderr}"
        end

        sections = ParseDebian822Service.new(result.stdout).execute

        sections.each_value.first
      end

      private

      def cmd
        @cmd ||= begin
          dpkg_deb_path = Gitlab.config.packages.dpkg_deb_path
          [dpkg_deb_path, '--field', @file_path]
        end
      end

      def result
        @result ||= Gitlab::Popen.popen_with_detail(cmd)
      end

      def success?
        result.status&.exitstatus == 0
      end
    end
  end
end