Module: Gitlab::ImportExport::CommandLineUtil

Constant Summary collapse

UNTAR_MASK =
'u+rwX,go+rX,go-w'
DEFAULT_DIR_MODE =
0700
CLEAN_DIR_IGNORE_FILE_NAMES =
%w[. ..].freeze
CommandLineUtilError =
Class.new(StandardError)
FileOversizedError =
Class.new(CommandLineUtilError)
HardLinkError =
Class.new(CommandLineUtilError)

Instance Method Summary collapse

Instance Method Details

#gunzip(dir:, filename:) ⇒ Object



34
35
36
# File 'lib/gitlab/import_export/command_line_util.rb', line 34

def gunzip(dir:, filename:)
  gzip_with_options(dir: dir, filename: filename, options: 'd')
end

#gzip(dir:, filename:) ⇒ Object



30
31
32
# File 'lib/gitlab/import_export/command_line_util.rb', line 30

def gzip(dir:, filename:)
  gzip_with_options(dir: dir, filename: filename)
end

#gzip_with_options(dir:, filename:, options: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/import_export/command_line_util.rb', line 38

def gzip_with_options(dir:, filename:, options: nil)
  filepath = File.join(dir, filename)
  cmd = %W[gzip #{filepath}]
  cmd << "-#{options}" if options

  _, status = Gitlab::Popen.popen(cmd)

  if status == 0
    status
  else
    raise Gitlab::ImportExport::Error.file_compression_error
  end
end

#mkdir_p(path) ⇒ Object



52
53
54
55
# File 'lib/gitlab/import_export/command_line_util.rb', line 52

def mkdir_p(path)
  FileUtils.mkdir_p(path, mode: DEFAULT_DIR_MODE)
  FileUtils.chmod(DEFAULT_DIR_MODE, path)
end

#tar_cf(archive:, dir:) ⇒ Object



22
23
24
# File 'lib/gitlab/import_export/command_line_util.rb', line 22

def tar_cf(archive:, dir:)
  tar_with_options(archive: archive, dir: dir, options: 'cf')
end

#tar_czf(archive:, dir:) ⇒ Object



14
15
16
# File 'lib/gitlab/import_export/command_line_util.rb', line 14

def tar_czf(archive:, dir:)
  tar_with_options(archive: archive, dir: dir, options: 'czf')
end

#untar_xf(archive:, dir:) ⇒ Object



26
27
28
# File 'lib/gitlab/import_export/command_line_util.rb', line 26

def untar_xf(archive:, dir:)
  untar_with_options(archive: archive, dir: dir, options: 'xf')
end

#untar_zxf(archive:, dir:) ⇒ Object



18
19
20
# File 'lib/gitlab/import_export/command_line_util.rb', line 18

def untar_zxf(archive:, dir:)
  untar_with_options(archive: archive, dir: dir, options: 'zxf')
end