Class: Gitlab::GithubImport::AttachmentsDownloader

Inherits:
Object
  • Object
show all
Includes:
BulkImports::FileDownloads::FilenameFetch, BulkImports::FileDownloads::Validations, ImportExport::CommandLineUtil
Defined in:
lib/gitlab/github_import/attachments_downloader.rb

Constant Summary collapse

DownloadError =
Class.new(StandardError)
UnsupportedAttachmentError =
Class.new(StandardError)
FILENAME_SIZE_LIMIT =

chars before the extension

255
DEFAULT_FILE_SIZE_LIMIT =
25.megabytes
TMP_DIR =
File.join(Dir.tmpdir, 'github_attachments').freeze

Constants included from BulkImports::FileDownloads::FilenameFetch

BulkImports::FileDownloads::FilenameFetch::REMOTE_FILENAME_PATTERN

Constants included from ImportExport::CommandLineUtil

ImportExport::CommandLineUtil::CLEAN_DIR_IGNORE_FILE_NAMES, ImportExport::CommandLineUtil::CommandLineUtilError, ImportExport::CommandLineUtil::DEFAULT_DIR_MODE, ImportExport::CommandLineUtil::FileOversizedError, ImportExport::CommandLineUtil::HardLinkError, ImportExport::CommandLineUtil::UNTAR_MASK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImportExport::CommandLineUtil

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

Constructor Details

#initialize(file_url, options: {}, file_size_limit: DEFAULT_FILE_SIZE_LIMIT) ⇒ AttachmentsDownloader

Returns a new instance of AttachmentsDownloader.



19
20
21
22
23
24
25
26
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 19

def initialize(file_url, options: {}, file_size_limit: DEFAULT_FILE_SIZE_LIMIT)
  @file_url = file_url
  @options = options
  @file_size_limit = file_size_limit

  filename = URI(file_url).path.split('/').last
  @filename = ensure_filename_size(filename)
end

Instance Attribute Details

#file_size_limitObject (readonly)

Returns the value of attribute file_size_limit.



17
18
19
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 17

def file_size_limit
  @file_size_limit
end

#file_urlObject (readonly)

Returns the value of attribute file_url.



17
18
19
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 17

def file_url
  @file_url
end

#filenameObject (readonly)

Returns the value of attribute filename.



17
18
19
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 17

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 17

def options
  @options
end

Instance Method Details

#deleteObject



39
40
41
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 39

def delete
  FileUtils.rm_rf File.dirname(filepath)
end

#performObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/github_import/attachments_downloader.rb', line 28

def perform
  validate_content_length
  validate_filepath

  redirection_url = get_assets_download_redirection_url
  file = download_from(redirection_url)

  validate_symlink
  file
end