diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-20 02:32:22 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-20 02:32:22 +0900 |
| commit | 66f52407d3a7f59fd7e2743fe1ccee7ad46df795 (patch) | |
| tree | be54701d1394f661e31e237395351cd95d86780a | |
| parent | e463faf6499fa537f6048857e10d123554112af6 (diff) | |
container/initmkdir: check path equivalence by value
Fixes regression introduced while integrating Absolute.
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | container/initmkdir.go | 8 | ||||
| -rw-r--r-- | container/initmkdir_test.go | 23 |
2 files changed, 30 insertions, 1 deletions
diff --git a/container/initmkdir.go b/container/initmkdir.go index 75256b27..3043df9f 100644 --- a/container/initmkdir.go +++ b/container/initmkdir.go @@ -29,6 +29,12 @@ func (m *MkdirOp) apply(*setupState) error { return wrapErrSelf(os.MkdirAll(toSysroot(m.Path.String()), m.Perm)) } -func (m *MkdirOp) Is(op Op) bool { vm, ok := op.(*MkdirOp); return ok && m == vm } +func (m *MkdirOp) Is(op Op) bool { + vm, ok := op.(*MkdirOp) + return ok && ((m == nil && vm == nil) || (m != nil && vm != nil && + m.Path != nil && vm.Path != nil && + m.Path.String() == vm.Path.String() && + m.Perm == vm.Perm)) +} func (*MkdirOp) prefix() string { return "creating" } func (m *MkdirOp) String() string { return fmt.Sprintf("directory %q perm %s", m.Path, m.Perm) } diff --git a/container/initmkdir_test.go b/container/initmkdir_test.go new file mode 100644 index 00000000..89058a85 --- /dev/null +++ b/container/initmkdir_test.go @@ -0,0 +1,23 @@ +package container + +import "testing" + +func TestMkdirOp(t *testing.T) { + checkOpsBuilder(t, []opsBuilderTestCase{ + {"etc", new(Ops).Mkdir(MustAbs("/etc/"), 0), Ops{ + &MkdirOp{Path: MustAbs("/etc/")}, + }}, + }) + + checkOpIs(t, []opIsTestCase{ + {"zero", new(MkdirOp), new(MkdirOp), false}, + {"differs", &MkdirOp{Path: MustAbs("/"), Perm: 0755}, &MkdirOp{Path: MustAbs("/etc/"), Perm: 0755}, false}, + {"equals", &MkdirOp{Path: MustAbs("/")}, &MkdirOp{Path: MustAbs("/")}, true}, + }) + + checkOpMeta(t, []opMetaTestCase{ + {"etc", &MkdirOp{ + Path: MustAbs("/etc/"), + }, "creating", `directory "/etc/" perm ----------`}, + }) +} |
