Class: BulkImports::FileDecompressionService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::ImportExport::CommandLineUtil
Defined in:
app/services/bulk_imports/file_decompression_service.rb

Constant Summary collapse

ServiceError =
Class.new(StandardError)

Constants included from Gitlab::ImportExport::CommandLineUtil

Gitlab::ImportExport::CommandLineUtil::DEFAULT_DIR_MODE, Gitlab::ImportExport::CommandLineUtil::FileOversizedError, Gitlab::ImportExport::CommandLineUtil::UNTAR_MASK

Instance Method Summary collapse

Methods included from Gitlab::ImportExport::CommandLineUtil

#gunzip, #gzip, #gzip_with_options, #mkdir_p, #tar_cf, #tar_czf, #untar_xf, #untar_zxf

Constructor Details

#initialize(tmpdir:, filename:) ⇒ FileDecompressionService

Returns a new instance of FileDecompressionService.


13
14
15
16
17
18
19
# File 'app/services/bulk_imports/file_decompression_service.rb', line 13

def initialize(tmpdir:, filename:)
  @tmpdir = tmpdir
  @filename = filename
  @filepath = File.join(@tmpdir, @filename)
  @decompressed_filename = File.basename(@filename, '.gz')
  @decompressed_filepath = File.join(@tmpdir, @decompressed_filename)
end

Instance Method Details

#executeObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/bulk_imports/file_decompression_service.rb', line 21

def execute
  validate_tmpdir
  validate_filepath
  validate_decompressed_file_size if Feature.enabled?(:validate_import_decompressed_archive_size)
  validate_symlink(filepath)

  decompress_file

  validate_symlink(decompressed_filepath)

  filepath
rescue StandardError => e
  File.delete(filepath) if File.exist?(filepath)
  File.delete(decompressed_filepath) if File.exist?(decompressed_filepath)

  raise e
end