debian-mirror-gitlab/app/models/import_export_upload.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class ImportExportUpload < ApplicationRecord
2018-11-08 19:23:39 +05:30
include WithUploads
belongs_to :project
2019-12-26 22:10:19 +05:30
belongs_to :group
2018-11-08 19:23:39 +05:30
2018-11-18 11:00:15 +05:30
# These hold the project Import/Export archives (.tar.gz files)
2018-11-08 19:23:39 +05:30
mount_uploader :import_file, ImportExportUploader
mount_uploader :export_file, ImportExportUploader
2021-09-04 01:27:46 +05:30
# This causes CarrierWave v1 and v3 (but not v2) to upload the file to
# object storage *after* the database entry has been committed to the
# database. This avoids idling in a transaction.
if Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_STORE_EXPORT_FILE_AFTER_COMMIT', true))
skip_callback :save, :after, :store_export_file!
set_callback :commit, :after, :store_export_file!
end
scope :updated_before, ->(date) { where('updated_at < ?', date) }
scope :with_export_file, -> { where.not(export_file: nil) }
2018-11-08 19:23:39 +05:30
def retrieve_upload(_identifier, paths)
Upload.find_by(model: self, path: paths)
end
2021-09-04 01:27:46 +05:30
def export_file_exists?
!!carrierwave_export_file
end
# This checks if the export archive is actually stored on disk. It
# requires a HEAD request if object storage is used.
def export_archive_exists?
!!carrierwave_export_file&.exists?
# Handle any HTTP unexpected error
# https://github.com/excon/excon/blob/bbb5bd791d0bb2251593b80e3bce98dbec6e8f24/lib/excon/error.rb#L129-L169
rescue Excon::Error => e
# The HEAD request will fail with a 403 Forbidden if the file does not
# exist, and the user does not have permission to list the object
# storage bucket.
Gitlab::ErrorTracking.track_exception(e)
false
end
private
def carrierwave_export_file
export_file&.file
end
2018-11-08 19:23:39 +05:30
end