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'")
fields = res.stdout.split("\n")
return {} if fields.length != 9
tmask = fields[1].to_i(16)
selinux = fields[8]
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
|