uploads_saver.rb 650 Bytes
Newer Older
James Lopez's avatar
James Lopez committed
1 2 3
module Gitlab
  module ImportExport
    class UploadsSaver
4 5
      include Gitlab::ImportExport::CommandLineUtil

James Lopez's avatar
James Lopez committed
6 7 8 9 10 11 12 13
      def initialize(project:, shared:)
        @project = project
        @shared = shared
      end

      def save
        return true unless File.directory?(uploads_path)

James Lopez's avatar
James Lopez committed
14
        copy_files(uploads_path, uploads_export_path)
James Lopez's avatar
James Lopez committed
15
      rescue => e
James Lopez's avatar
James Lopez committed
16
        @shared.error(e)
James Lopez's avatar
James Lopez committed
17 18 19 20 21 22 23 24 25 26
        false
      end

      private

      def uploads_export_path
        File.join(@shared.export_path, 'uploads')
      end

      def uploads_path
James Lopez's avatar
James Lopez committed
27
        File.join(Rails.root.join('public/uploads'), @project.path_with_namespace)
James Lopez's avatar
James Lopez committed
28 29 30 31
      end
    end
  end
end