command_line_util.rb 1.16 KB
Newer Older
1
module Gitlab
2 3 4
  module ImportExport
    module CommandLineUtil
      def tar_cf(archive:, dir:)
5 6 7
        tar_with_options(archive: archive, dir: dir, options: 'cf')
      end

8 9
      def untar_zxf(archive:, dir:)
        untar_with_options(archive: archive, dir: dir, options: 'zxf')
10 11
      end

12 13
      def untar_czf(archive:, dir:)
        untar_with_options(archive: archive, dir: dir, options: 'xf')
14 15
      end

16 17
      def tar_czf(archive:, dir:)
        tar_with_options(archive: archive, dir: dir, options: 'czf')
18
      end
19 20 21 22 23 24

      def git_bundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:)
        cmd = %W(#{git_bin_path} --git-dir=#{repo_path} bundle create #{bundle_path} --all)
        _output, status = Gitlab::Popen.popen(cmd)
        status.zero?
      end
25 26

      def tar_with_options(archive:, dir:, options:)
27
        cmd = %W(tar -#{options} #{archive} #{dir})
28 29 30
        _output, status = Gitlab::Popen.popen(cmd)
        status.zero?
      end
31 32 33 34 35 36

      def untar_with_options(archive:, dir:, options:)
        cmd = %W(tar -#{options} #{archive} -C #{dir})
        _output, status = Gitlab::Popen.popen(cmd)
        status.zero?
      end
37 38 39
    end
  end
end