debian-mirror-gitlab/lib/gitlab/import_export/avatar_restorer.rb

33 lines
675 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
module Gitlab
module ImportExport
class AvatarRestorer
def initialize(project:, shared:)
@project = project
@shared = shared
end
def restore
return true unless avatar_export_file
@project.avatar = File.open(avatar_export_file)
@project.save!
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2016-08-24 12:49:21 +05:30
@shared.error(e)
false
end
private
def avatar_export_file
2018-11-20 20:47:30 +05:30
@avatar_export_file ||= Dir["#{avatar_export_path}/**/*"].find { |f| File.file?(f) }
2016-08-24 12:49:21 +05:30
end
def avatar_export_path
File.join(@shared.export_path, 'avatar')
end
end
end
end