Module: Gitlab::ImportExport::CommandLineUtil

Constant Summary collapse

UNTAR_MASK =
'u+rwX,go+rX,go-w'
DEFAULT_DIR_MODE =
0700
FileOversizedError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#gunzip(dir:, filename:) ⇒ Object


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

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

#gzip(dir:, filename:) ⇒ Object


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

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

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


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/import_export/command_line_util.rb', line 35

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


49
50
51
52
# File 'lib/gitlab/import_export/command_line_util.rb', line 49

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

#tar_cf(archive:, dir:) ⇒ Object


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

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

#tar_czf(archive:, dir:) ⇒ Object


11
12
13
# File 'lib/gitlab/import_export/command_line_util.rb', line 11

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

#untar_xf(archive:, dir:) ⇒ Object


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

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

#untar_zxf(archive:, dir:) ⇒ Object


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

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