From 7e7d6ee4297144dd29f98343ec2874c8e28b66fe Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Mon, 20 May 2024 14:26:58 +0800 Subject: [PATCH 1/2] add test case for special character --- pkg/meta/base_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/meta/base_test.go b/pkg/meta/base_test.go index c47e764237fe..4a4d9c6ebf6a 100644 --- a/pkg/meta/base_test.go +++ b/pkg/meta/base_test.go @@ -789,6 +789,15 @@ func testMetaClient(t *testing.T, m Meta) { if st := m.SetXattr(ctx, inode, "a", []byte("v5"), 5); st != syscall.EINVAL { t.Fatalf("setxattr: %s", st) } + if st := m.SetXattr(ctx, inode, "R", []byte("value"), 0); st != 0 { + t.Fatalf("setxattr special: %s", st) + } + if st := m.SetXattr(ctx, inode, "\x8ar", []byte("E$\xfe"), XattrCreate); st != 0 { + t.Fatalf("setxattr special: %s", st) + } + if st := m.GetXattr(ctx, inode, "\x8ar", &value); st != 0 || string(value) != "E$\xfe" { + t.Fatalf("getxattr special: %s", st) + } var totalspace, availspace, iused, iavail uint64 if st := m.StatFS(ctx, RootInode, &totalspace, &availspace, &iused, &iavail); st != 0 { From 878d184a5e4066901b84800767f64df134807ad7 Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Mon, 20 May 2024 14:27:12 +0800 Subject: [PATCH 2/2] use binary as column type --- pkg/meta/sql.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index a03bb8bd2a12..6a15e6fe6dda 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -166,7 +166,7 @@ type symlink struct { type xattr struct { Id int64 `xorm:"pk bigserial"` Inode Ino `xorm:"unique(name) notnull"` - Name string `xorm:"unique(name) notnull"` + Name []byte `xorm:"unique(name) varbinary(255) notnull"` Value []byte `xorm:"blob notnull"` } @@ -3070,7 +3070,7 @@ func (m *dbMeta) GetXattr(ctx Context, inode Ino, name string, vbuff *[]byte) sy defer m.timeit("GetXattr", time.Now()) inode = m.checkRoot(inode) return errno(m.roTxn(func(s *xorm.Session) error { - var x = xattr{Inode: inode, Name: name} + var x = xattr{Inode: inode, Name: []byte(name)} ok, err := s.Get(&x) if err != nil { return err @@ -3114,8 +3114,8 @@ func (m *dbMeta) ListXattr(ctx Context, inode Ino, names *[]byte) syscall.Errno func (m *dbMeta) doSetXattr(ctx Context, inode Ino, name string, value []byte, flags uint32) syscall.Errno { return errno(m.txn(func(s *xorm.Session) error { - var k = &xattr{Inode: inode, Name: name} - var x = xattr{Inode: inode, Name: name, Value: value} + var k = &xattr{Inode: inode, Name: []byte(name)} + var x = xattr{Inode: inode, Name: []byte(name), Value: value} ok, err := s.ForUpdate().Get(k) if err != nil { return err @@ -3145,7 +3145,7 @@ func (m *dbMeta) doSetXattr(ctx Context, inode Ino, name string, value []byte, f func (m *dbMeta) doRemoveXattr(ctx Context, inode Ino, name string) syscall.Errno { return errno(m.txn(func(s *xorm.Session) error { - n, err := s.Delete(&xattr{Inode: inode, Name: name}) + n, err := s.Delete(&xattr{Inode: inode, Name: []byte(name)}) if err != nil { return err } else if n == 0 { @@ -3281,7 +3281,7 @@ func (m *dbMeta) dumpEntry(s *xorm.Session, inode Ino, typ uint8, e *DumpedEntry if len(rows) > 0 { xattrs := make([]*DumpedXattr, 0, len(rows)) for _, x := range rows { - xattrs = append(xattrs, &DumpedXattr{x.Name, string(x.Value)}) + xattrs = append(xattrs, &DumpedXattr{string(x.Name), string(x.Value)}) } sort.Slice(xattrs, func(i, j int) bool { return xattrs[i].Name < xattrs[j].Name }) e.Xattrs = xattrs @@ -3375,7 +3375,7 @@ func (m *dbMeta) dumpEntryFast(inode Ino, typ uint8) *DumpedEntry { if ok && len(rows) > 0 { xattrs := make([]*DumpedXattr, 0, len(rows)) for _, x := range rows { - xattrs = append(xattrs, &DumpedXattr{x.Name, string(x.Value)}) + xattrs = append(xattrs, &DumpedXattr{string(x.Name), string(x.Value)}) } sort.Slice(xattrs, func(i, j int) bool { return xattrs[i].Name < xattrs[j].Name }) e.Xattrs = xattrs @@ -3848,7 +3848,7 @@ func (m *dbMeta) loadEntry(e *DumpedEntry, chs []chan interface{}, aclMaxId *uin chs[5] <- &symlink{inode, symL} } for _, x := range e.Xattrs { - chs[4] <- &xattr{Inode: inode, Name: x.Name, Value: unescape(x.Value)} + chs[4] <- &xattr{Inode: inode, Name: []byte(x.Name), Value: unescape(x.Value)} } n.AccessACLId = m.saveACL(loadACL(e.AccessACL), aclMaxId)