Skip to content

Commit 6d85d37

Browse files
committed
Make stat command use '-c' for Yocto OS
Signed-off-by: Michael Lihs <[email protected]>
1 parent 19ceb02 commit 6d85d37

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/train/extras/stat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def self.stat(shell_escaped_path, backend, follow_symlink)
3535

3636
def self.linux_stat(shell_escaped_path, backend, follow_symlink)
3737
lstat = follow_symlink ? " -L" : ""
38-
format = (backend.os.esx? || backend.os[:name] == "alpine") ? "-c" : "--printf"
38+
format = (backend.os.esx? || backend.os[:name] == "alpine" || backend.os[:name] == "yocto") ? "-c" : "--printf"
3939
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'")
4040
# ignore the exit_code: it is != 0 if selinux labels are not supported
4141
# on the system.

test/unit/extras/stat_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@
131131
end
132132
end
133133

134+
describe "yocto stat" do
135+
let(:backend) do
136+
mock = Train::Transports::Mock.new(verbose: true).connection
137+
mock.mock_os({ name: "yocto", family: "yocto", release: nil })
138+
mock.commands = {
139+
"stat /path 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command("", "", "", 0),
140+
"stat /path-stat 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command("", "360\n43ff\nroot\n0\nrootz\n1\n1444520846\n1444522445\n?", "", 0),
141+
}
142+
mock
143+
end
144+
145+
it "ignores wrong stat results" do
146+
_(cls.linux_stat("/path", backend, false)).must_equal({})
147+
end
148+
149+
it "reads correct stat results" do
150+
_(cls.linux_stat("/path-stat", backend, false)).must_equal({
151+
type: :directory,
152+
mode: 01777,
153+
owner: "root",
154+
uid: 0,
155+
group: "rootz",
156+
gid: 1,
157+
mtime: 1444522445,
158+
size: 360,
159+
selinux_label: nil,
160+
})
161+
end
162+
end
163+
134164
describe "bsd stat" do
135165
let(:backend) { Minitest::Mock.new }
136166

0 commit comments

Comments
 (0)