Skip to content

Commit 95565b7

Browse files
committed
vfs: workaround for a maps.Clone bug
Stop using `maps.Clone` because of golang/go#69110 Fixes #3894
1 parent 34e929e commit 95565b7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

vfs/mem_fs.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"fmt"
1010
"io"
11-
"maps"
1211
"math/rand"
1312
"os"
1413
"path"
@@ -138,7 +137,7 @@ type CrashCloneCfg struct {
138137
// latter is controlled by CrashCloneCfg.
139138
func (y *MemFS) CrashClone(cfg CrashCloneCfg) *MemFS {
140139
if !y.crashable {
141-
panic("not a strict MemFS")
140+
panic("not a crashable MemFS")
142141
}
143142
// Block all modification operations while we clone.
144143
y.cloneMu.Lock()
@@ -635,10 +634,11 @@ func newRootMemNode() *memNode {
635634
}
636635

637636
func cloneChildren(f map[string]*memNode) map[string]*memNode {
638-
if len(f) == 0 {
639-
return make(map[string]*memNode)
637+
m := make(map[string]*memNode)
638+
for k, v := range f {
639+
m[k] = v
640640
}
641-
return maps.Clone(f)
641+
return m
642642
}
643643

644644
func (f *memNode) dump(w *bytes.Buffer, level int, name string) {
@@ -671,6 +671,8 @@ func (f *memNode) dump(w *bytes.Buffer, level int, name string) {
671671
}
672672
}
673673

674+
// CrashClone creates a crash-consistent clone of the subtree rooted at f, and
675+
// returns the new subtree. cloneMu must be held (in write mode).
674676
func (f *memNode) CrashClone(cfg *CrashCloneCfg) *memNode {
675677
newNode := &memNode{isDir: f.isDir}
676678
if f.isDir {

0 commit comments

Comments
 (0)