Skip to content

Make stat command use '-c' for Yocto OS #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/train/extras/stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.stat(shell_escaped_path, backend, follow_symlink)

def self.linux_stat(shell_escaped_path, backend, follow_symlink)
lstat = follow_symlink ? " -L" : ""
format = (backend.os.esx? || backend.os[:name] == "alpine") ? "-c" : "--printf"
format = (backend.os.esx? || backend.os[:name] == "alpine" || backend.os[:name] == "yocto") ? "-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.
Expand Down
30 changes: 30 additions & 0 deletions test/unit/extras/stat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@
end
end

describe "yocto stat" do
let(:backend) do
mock = Train::Transports::Mock.new(verbose: true).connection
mock.mock_os({ name: "yocto", family: "yocto", release: nil })
mock.commands = {
"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),
"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),
}
mock
end

it "ignores wrong stat results" do
_(cls.linux_stat("/path", backend, false)).must_equal({})
end

it "reads correct stat results" do
_(cls.linux_stat("/path-stat", backend, false)).must_equal({
type: :directory,
mode: 01777,
owner: "root",
uid: 0,
group: "rootz",
gid: 1,
mtime: 1444522445,
size: 360,
selinux_label: nil,
})
end
end

describe "bsd stat" do
let(:backend) { Minitest::Mock.new }

Expand Down