This commit is contained in:
xuyuchao
2025-12-03 17:24:24 +08:00
parent 141ae18d60
commit f918f78161

View File

@@ -2623,14 +2623,11 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
}
type entryInfo struct {
e *edge
trash Ino
n *node // n edges : 1 inode
opened bool // node is opened
e *edge
trash Ino
n *node // n edges : 1 inode
opened bool // node is opened
trashName string
lastLink bool
}
var entryInfos []entryInfo
var totalLength, totalSpace, totalInodes int64
@@ -2657,7 +2654,6 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
if (pn.Flags&FlagAppend != 0) || (pn.Flags&FlagImmutable) != 0 {
return syscall.EPERM
}
entryInfos = make([]entryInfo, 0, len(entries))
now := time.Now().UnixNano()
@@ -2719,19 +2715,17 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
te := edge{
Parent: info.trash,
Name: []byte(info.trashName),
Inode: info.e.Inode,
Type: info.e.Type,
Inode: info.n.Inode,
Type: info.n.Type,
}
if ok, err := s.Get(&te); err == nil && ok {
info.trash = 0
}
}
info.n.setCtime(now)
if info.trash > 0 && info.n.Parent > 0 {
info.n.Parent = info.trash
}
if info.trash == 0 {
info.n.Nlink--
if info.n.Type == TypeFile && info.n.Nlink == 0 && m.sid > 0 {
@@ -2744,23 +2738,26 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
visited := make(map[Ino]bool)
visited[0] = true // skip dummyNode
for _, info := range entryInfos {
if info.e.Type == TypeDirectory {
if info.n.Type == TypeDirectory {
continue
}
e := edge{Parent: parent, Name: info.e.Name}
if _, err := s.Delete(&e); err != nil {
return err
}
if !visited[info.n.Inode] {
if info.n.Nlink > 0 {
if _, err := s.Cols("nlink", "ctime", "ctimensec", "parent").Update(&info.n, &node{Inode: info.n.Inode}); err != nil {
if _, err := s.Cols("nlink", "ctime", "ctimensec", "parent").Update(info.n, &node{Inode: info.n.Inode}); err != nil {
return err
}
if info.n.Type == TypeFile {
entrySpace := align4K(info.n.Length)
recordDeletionStats(info.n, entrySpace, 0, &totalLength, &totalSpace, &totalInodes, userGroupQuotas, parent.IsTrash())
}
} else {
var entrySpace int64
needRecordStats := false
switch info.e.Type {
switch info.n.Type {
case TypeFile:
entrySpace = align4K(info.n.Length)
needRecordStats = true
@@ -2768,7 +2765,7 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
if err := mustInsert(s, &sustained{Sid: m.sid, Inode: info.e.Inode}); err != nil {
return err
}
if _, err := s.Cols("nlink", "ctime", "ctimensec").Update(&info.n, &node{Inode: info.n.Inode}); err != nil {
if _, err := s.Cols("nlink", "ctime", "ctimensec").Update(info.n, &node{Inode: info.n.Inode}); err != nil {
return err
}
} else {
@@ -2788,12 +2785,12 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
if _, err := s.Delete(&node{Inode: info.e.Inode}); err != nil {
return err
}
if info.e.Type != TypeFile {
if info.n.Type != TypeFile {
entrySpace = align4K(0)
needRecordStats = true
}
}
if needRecordStats {
if needRecordStats && info.n.Inode != 0 {
recordDeletionStats(info.n, entrySpace, entrySpace, &totalLength, &totalSpace, &totalInodes, userGroupQuotas, parent.IsTrash())
}
if _, err := s.Delete(&xattr{Inode: info.e.Inode}); err != nil {
@@ -2809,8 +2806,8 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
if err = mustInsert(s, &edge{
Parent: info.trash,
Name: []byte(info.trashName),
Inode: e.Inode,
Type: e.Type}); err != nil {
Inode: info.n.Inode,
Type: info.n.Type}); err != nil {
return err
}
}
@@ -2835,7 +2832,9 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
m.fileDeleted(info.opened, parent.IsTrash(), info.e.Inode, info.n.Length)
}
}
m.updateStats(totalSpace, totalInodes)
if trash == 0 {
m.updateStats(totalSpace, totalInodes)
}
*length = totalLength
*space = totalSpace
*inodes = totalInodes