Method: Train::Extras::Stat.linux_stat

Defined in:
lib/train/extras/stat.rb

.linux_stat(shell_escaped_path, backend, follow_symlink) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/train/extras/stat.rb', line 35

def self.linux_stat(shell_escaped_path, backend, follow_symlink)
  lstat = follow_symlink ? ' -L' : ''
  format = (backend.os.esx? || backend.os[:name] == 'alpine') ? '-c' : '--printf'
  res = backend.run_command("stat#{lstat} #{shell_escaped_path} 2>/dev/null #{format} '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'")
  # ignore the exit_code: it is != 0 if selinux labels are not supported
  # on the system.

  fields = res.stdout.split("\n")
  return {} if fields.length != 9

  tmask = fields[1].to_i(16)
  selinux = fields[8]
  ## selinux security context string not available on esxi
  selinux = nil if selinux == '?' or selinux == '(null)' or selinux == 'C'
  {
    type:  find_type(tmask),
    mode:  tmask & 07777,
    owner: fields[2],
    uid:   fields[3].to_i,
    group: fields[4],
    gid:   fields[5].to_i,
    mtime: fields[7].to_i,
    size:  fields[0].to_i,
    selinux_label: selinux,
  }
end