mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
Merge pull request #11912 from chenk008/fix_roofs_path_contains_colon
support rootfs contains colon
This commit is contained in:
@ -552,10 +552,10 @@ func NewSpecGenerator(arg string, rootfs bool) *SpecGenerator {
|
|||||||
if rootfs {
|
if rootfs {
|
||||||
csc.Rootfs = arg
|
csc.Rootfs = arg
|
||||||
// check if rootfs is actually overlayed
|
// check if rootfs is actually overlayed
|
||||||
parts := strings.SplitN(csc.Rootfs, ":", 2)
|
lastColonIndex := strings.LastIndex(csc.Rootfs, ":")
|
||||||
if len(parts) > 1 && parts[1] == "O" {
|
if lastColonIndex != -1 && lastColonIndex+1 < len(csc.Rootfs) && csc.Rootfs[lastColonIndex+1:] == "O" {
|
||||||
csc.RootfsOverlay = true
|
csc.RootfsOverlay = true
|
||||||
csc.Rootfs = parts[0]
|
csc.Rootfs = csc.Rootfs[:lastColonIndex]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
csc.Image = arg
|
csc.Image = arg
|
||||||
|
25
pkg/specgen/specgen_test.go
Normal file
25
pkg/specgen/specgen_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user