blob: fa7a84ee3d64cbe37f775986dd08c7f1c0350a9e (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# frozen_string_literal: true
module Packages
module Nuget
class ProcessPackageFileService
ExtractionError = Class.new(StandardError)
NUGET_SYMBOL_FILE_EXTENSION = '.snupkg'
def initialize(package_file)
@package_file = package_file
end
def execute
raise ExtractionError, 'invalid package file' unless valid_package_file?
nuspec_content = nil
with_zip_file do |zip_file|
nuspec_content = nuspec_file_content(zip_file)
create_symbol_files(zip_file) if symbol_package_file?
end
ServiceResponse.success(payload: { nuspec_file_content: nuspec_content })
end
private
attr_reader :package_file
def valid_package_file?
package_file &&
package_file.package&.nuget? &&
package_file.file.size > 0 # rubocop:disable Style/ZeroLengthPredicate
end
def with_zip_file(&block)
package_file.file.use_open_file(unlink_early: false) do |open_file|
Zip::File.open(open_file.file_path, &block) # rubocop: disable Performance/Rubyzip
end
end
def nuspec_file_content(zip_file)
::Packages::Nuget::ExtractMetadataFileService
.new(zip_file)
.execute
.payload
end
def create_symbol_files(zip_file)
::Packages::Nuget::Symbols::CreateSymbolFilesService
.new(package_file.package, zip_file)
.execute
end
def symbol_package_file?
package_file.file_name.end_with?(NUGET_SYMBOL_FILE_EXTENSION)
end
end
end
end
|