Skip to content

Commit

Permalink
Fix package query fails on debian based container (#519) (#522)
Browse files Browse the repository at this point in the history
* Fix package query fails on debian based container (#519)

* Fix executil test (#519)
  • Loading branch information
nashiox authored and kotakanbe committed Oct 25, 2017
1 parent 10d690d commit e137ebb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scan/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (o *debian) rebootRequired() (bool, error) {

func (o *debian) scanInstalledPackages() (models.Packages, models.Packages, models.SrcPackages, error) {
installed, updatable, srcPacks := models.Packages{}, models.Packages{}, models.SrcPackages{}
r := o.exec(`dpkg-query -W -f='${binary:Package},${db:Status-Abbrev},${Version},${Source},${source:Version}\n'`, noSudo)
r := o.exec(`dpkg-query -W -f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n"`, noSudo)
if !r.isSuccess() {
return nil, nil, nil, fmt.Errorf("Failed to SSH: %s", r)
}
Expand Down
4 changes: 2 additions & 2 deletions scan/executil.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ func decorateCmd(c conf.ServerInfo, cmd string, sudo bool) string {
if c.IsContainer() {
switch c.Containers.Type {
case "", "docker":
cmd = fmt.Sprintf(`docker exec --user 0 %s /bin/bash -c "%s"`, c.Container.ContainerID, cmd)
cmd = fmt.Sprintf(`docker exec --user 0 %s /bin/bash -c '%s'`, c.Container.ContainerID, cmd)
case "lxd":
cmd = fmt.Sprintf(`lxc exec %s -- /bin/bash -c "%s"`, c.Container.Name, cmd)
cmd = fmt.Sprintf(`lxc exec %s -- /bin/bash -c '%s'`, c.Container.Name, cmd)
}
}
// cmd = fmt.Sprintf("set -x; %s", cmd)
Expand Down
20 changes: 10 additions & 10 deletions scan/executil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: false,
expected: `docker exec --user 0 abc /bin/bash -c "ls"`,
expected: `docker exec --user 0 abc /bin/bash -c 'ls'`,
},
// root sudo true docker
{
Expand All @@ -86,7 +86,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: true,
expected: `docker exec --user 0 abc /bin/bash -c "ls"`,
expected: `docker exec --user 0 abc /bin/bash -c 'ls'`,
},
// non-root sudo false, docker
{
Expand All @@ -97,7 +97,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: false,
expected: `docker exec --user 0 abc /bin/bash -c "ls"`,
expected: `docker exec --user 0 abc /bin/bash -c 'ls'`,
},
// non-root sudo true, docker
{
Expand All @@ -108,7 +108,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: true,
expected: `docker exec --user 0 abc /bin/bash -c "ls"`,
expected: `docker exec --user 0 abc /bin/bash -c 'ls'`,
},
// non-root sudo true, docker
{
Expand All @@ -119,7 +119,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls | grep hoge",
sudo: true,
expected: `docker exec --user 0 abc /bin/bash -c "ls | grep hoge"`,
expected: `docker exec --user 0 abc /bin/bash -c 'ls | grep hoge'`,
},
// -------------lxd-------------
// root sudo false lxd
Expand All @@ -131,7 +131,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: false,
expected: `lxc exec def -- /bin/bash -c "ls"`,
expected: `lxc exec def -- /bin/bash -c 'ls'`,
},
// root sudo true lxd
{
Expand All @@ -142,7 +142,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: true,
expected: `lxc exec def -- /bin/bash -c "ls"`,
expected: `lxc exec def -- /bin/bash -c 'ls'`,
},
// non-root sudo false, lxd
{
Expand All @@ -153,7 +153,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: false,
expected: `lxc exec def -- /bin/bash -c "ls"`,
expected: `lxc exec def -- /bin/bash -c 'ls'`,
},
// non-root sudo true, lxd
{
Expand All @@ -164,7 +164,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls",
sudo: true,
expected: `lxc exec def -- /bin/bash -c "ls"`,
expected: `lxc exec def -- /bin/bash -c 'ls'`,
},
// non-root sudo true lxd
{
Expand All @@ -175,7 +175,7 @@ func TestDecorateCmd(t *testing.T) {
},
cmd: "ls | grep hoge",
sudo: true,
expected: `lxc exec def -- /bin/bash -c "ls | grep hoge"`,
expected: `lxc exec def -- /bin/bash -c 'ls | grep hoge'`,
},
}

Expand Down

0 comments on commit e137ebb

Please sign in to comment.