From dcd6efedb6dd0fe7712ecda86470ba8e502a0594 Mon Sep 17 00:00:00 2001 From: zhijian Date: Wed, 15 May 2024 19:50:08 +0800 Subject: [PATCH] cmd/clone: fix src mode check (#4856) --- pkg/meta/redis.go | 9 +++++---- pkg/meta/tkv.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index 2f809a8398ce..2c4be7f96afb 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -4212,14 +4212,15 @@ func (m *redisMeta) LoadMeta(r io.Reader) (err error) { return err } -func (m *redisMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name string, ino Ino, attr *Attr, cmode uint8, cumask uint16, top bool) syscall.Errno { +func (m *redisMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name string, ino Ino, originAttr *Attr, cmode uint8, cumask uint16, top bool) syscall.Errno { return errno(m.txn(ctx, func(tx *redis.Tx) error { a, err := tx.Get(ctx, m.inodeKey(srcIno)).Bytes() if err != nil { return err } - m.parseAttr(a, attr) - if eno := m.Access(ctx, srcIno, MODE_MASK_R, attr); eno != 0 { + m.parseAttr(a, originAttr) + attr := *originAttr + if eno := m.Access(ctx, srcIno, MODE_MASK_R, &attr); eno != 0 { return eno } attr.Parent = parent @@ -4268,7 +4269,7 @@ func (m *redisMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name strin } _, err = tx.TxPipelined(ctx, func(p redis.Pipeliner) error { - p.Set(ctx, m.inodeKey(ino), m.marshal(attr), 0) + p.Set(ctx, m.inodeKey(ino), m.marshal(&attr), 0) p.IncrBy(ctx, m.usedSpaceKey(), align4K(attr.Length)) p.Incr(ctx, m.totalInodesKey()) if len(srcXattr) > 0 { diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index b09d9f087c83..78c89e51aba9 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -3359,14 +3359,15 @@ func (m *kvMeta) LoadMeta(r io.Reader) error { }) } -func (m *kvMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name string, ino Ino, attr *Attr, cmode uint8, cumask uint16, top bool) syscall.Errno { +func (m *kvMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name string, ino Ino, originAttr *Attr, cmode uint8, cumask uint16, top bool) syscall.Errno { return errno(m.txn(func(tx *kvTxn) error { a := tx.get(m.inodeKey(srcIno)) if a == nil { return syscall.ENOENT } - m.parseAttr(a, attr) - if eno := m.Access(ctx, srcIno, MODE_MASK_R, attr); eno != 0 { + m.parseAttr(a, originAttr) + attr := *originAttr + if eno := m.Access(ctx, srcIno, MODE_MASK_R, &attr); eno != 0 { return eno } attr.Parent = parent @@ -3416,7 +3417,7 @@ func (m *kvMeta) doCloneEntry(ctx Context, srcIno Ino, parent Ino, name string, } } - tx.set(m.inodeKey(ino), m.marshal(attr)) + tx.set(m.inodeKey(ino), m.marshal(&attr)) prefix := m.xattrKey(srcIno, "") tx.scan(prefix, nextKey(prefix), false, func(k, v []byte) bool { tx.set(m.xattrKey(ino, string(k[len(prefix):])), v)