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

meta: delete hardlinks directly if there's already same entry in the trash #3706

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,10 @@ func (m *redisMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, s
if (attr.Flags&FlagAppend) != 0 || (attr.Flags&FlagImmutable) != 0 {
return syscall.EPERM
}
if trash > 0 && attr.Nlink > 1 && tx.HExists(ctx, m.entryKey(trash), m.trashEntry(parent, inode, name)).Val() {
trash = 0
defer func() { m.of.InvalidateChunk(inode, invalidateAttrOnly) }()
}
attr.Ctime = now.Unix()
attr.Ctimensec = uint32(now.Nanosecond())
if trash == 0 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@ func (m *dbMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip
if (n.Flags&FlagAppend) != 0 || (n.Flags&FlagImmutable) != 0 {
return syscall.EPERM
}
if trash > 0 && n.Nlink > 1 {
if o, e := s.Get(&edge{Parent: trash, Name: []byte(m.trashEntry(parent, e.Inode, string(e.Name))), Inode: e.Inode, Type: e.Type}); e == nil && o {
trash = 0
}
}
n.Ctime = now / 1e3
n.Ctimensec = int16(now % 1e3)
if trash == 0 {
Expand Down
9 changes: 8 additions & 1 deletion pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,11 @@ func (m *kvMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip
if _type == TypeDirectory {
return syscall.EPERM
}
rs := tx.gets(m.inodeKey(parent), m.inodeKey(inode))
keys := [][]byte{m.inodeKey(parent), m.inodeKey(inode)}
if trash > 0 {
keys = append(keys, m.entryKey(trash, m.trashEntry(parent, inode, name)))
}
rs := tx.gets(keys...)
if rs[0] == nil {
return syscall.ENOENT
}
Expand All @@ -1258,6 +1262,9 @@ func (m *kvMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip
if (attr.Flags&FlagAppend) != 0 || (attr.Flags&FlagImmutable) != 0 {
return syscall.EPERM
}
if trash > 0 && attr.Nlink > 1 && rs[2] != nil {
trash = 0
}
attr.Ctime = now.Unix()
attr.Ctimensec = uint32(now.Nanosecond())
if trash == 0 {
Expand Down