Skip to content

Commit

Permalink
Merge pull request containers#11912 from chenk008/fix_roofs_path_cont…
Browse files Browse the repository at this point in the history
…ains_colon

support rootfs contains colon
  • Loading branch information
openshift-merge-robot authored Oct 11, 2021
2 parents dd9c917 + 54471ac commit 00ebf3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/specgen/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ func NewSpecGenerator(arg string, rootfs bool) *SpecGenerator {
if rootfs {
csc.Rootfs = arg
// check if rootfs is actually overlayed
parts := strings.SplitN(csc.Rootfs, ":", 2)
if len(parts) > 1 && parts[1] == "O" {
lastColonIndex := strings.LastIndex(csc.Rootfs, ":")
if lastColonIndex != -1 && lastColonIndex+1 < len(csc.Rootfs) && csc.Rootfs[lastColonIndex+1:] == "O" {
csc.RootfsOverlay = true
csc.Rootfs = parts[0]
csc.Rootfs = csc.Rootfs[:lastColonIndex]
}
} else {
csc.Image = arg
Expand Down
25 changes: 25 additions & 0 deletions pkg/specgen/specgen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package specgen

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewSpecGeneratorWithRootfs(t *testing.T) {
tests := []struct {
rootfs string
expectedRootfsOverlay bool
expectedRootfs string
}{
{"/root/a:b:O", true, "/root/a:b"},
{"/root/a:b/c:O", true, "/root/a:b/c"},
{"/root/a:b/c:", false, "/root/a:b/c:"},
{"/root/a/b", false, "/root/a/b"},
}
for _, args := range tests {
val := NewSpecGenerator(args.rootfs, true)
assert.Equal(t, val.RootfsOverlay, args.expectedRootfsOverlay)
assert.Equal(t, val.Rootfs, args.expectedRootfs)
}
}

0 comments on commit 00ebf3c

Please sign in to comment.