summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/saver.rb
blob: dd4fdf373092be0bae390f137b538bd79c607b2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Gitlab
  module ImportExport
    class Saver
      include Gitlab::ImportExport::CommandLineUtil

      def self.save(*args)
        new(*args).save
      end

      def initialize(shared:)
        @shared = shared
      end

      def save
        if compress_and_save
          remove_export_path
          Rails.logger.info("Saved project export #{archive_file}")
          archive_file
        else
          @shared.error("Unable to save #{archive_file} into #{@shared.export_path}")
          false
        end
      rescue => e
        @shared.error(e)
        false
      end

      private

      def compress_and_save
        tar_czf(archive: archive_file, dir: @shared.export_path)
      end

      def remove_export_path
        FileUtils.rm_rf(@shared.export_path)
      end

      def archive_file
        @archive_file ||= File.join(@shared.export_path, '..', "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_project_export.tar.gz")
      end
    end
  end
end