Skip to content

Commit

Permalink
vfs: work around a maps.Clone bug
Browse files Browse the repository at this point in the history
Stop using `maps.Clone` because of golang/go#69110

Fixes cockroachdb#3894
  • Loading branch information
RaduBerinde committed Aug 28, 2024
1 parent a70d5b3 commit b2c26ff
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vfs/mem_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
"maps"
"math/rand"
"os"
"path"
Expand Down Expand Up @@ -138,7 +137,7 @@ type CrashCloneCfg struct {
// latter is controlled by CrashCloneCfg.
func (y *MemFS) CrashClone(cfg CrashCloneCfg) *MemFS {
if !y.crashable {
panic("not a strict MemFS")
panic("not a crashable MemFS")
}
// Block all modification operations while we clone.
y.cloneMu.Lock()
Expand Down Expand Up @@ -635,10 +634,11 @@ func newRootMemNode() *memNode {
}

func cloneChildren(f map[string]*memNode) map[string]*memNode {
if len(f) == 0 {
return make(map[string]*memNode)
m := make(map[string]*memNode)
for k, v := range f {
m[k] = v
}
return maps.Clone(f)
return m
}

func (f *memNode) dump(w *bytes.Buffer, level int, name string) {
Expand Down Expand Up @@ -671,6 +671,8 @@ func (f *memNode) dump(w *bytes.Buffer, level int, name string) {
}
}

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

0 comments on commit b2c26ff

Please sign in to comment.