Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfs: workaround for a maps.Clone bug #3895

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading