Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Feb 19, 2025
1 parent 2bea56e commit 9a11446
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1873,9 +1873,15 @@ func testTrash(t *testing.T, m Meta) {
if st := m.GetAttr(ctx, inode, attr); st != 0 || attr.Parent != TrashInode+1 {
t.Fatalf("getattr f(%d): %s, attr %+v", inode, st, attr)
}
if st := m.Truncate(ctx, inode, 0, 1<<30, attr, false); st != syscall.EPERM {
t.Fatalf("should not truncate a file in trash")
}
if st := m.Open(ctx, inode, uint32(syscall.O_RDWR), attr); st != syscall.EPERM {
t.Fatalf("should not fallocate a file in trash")
}
if st := m.SetAttr(ctx, inode, SetAttrMode, 1, &Attr{Mode: 0}); st != syscall.EPERM {
t.Fatalf("should not change mode of a file in trash")
}
var parent2 Ino
if st := m.Mkdir(ctx, 1, "d2", 0755, 022, 0, &parent2, attr); st != 0 {
t.Fatalf("mkdir d2: %s", st)
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func (m *redisMeta) doTruncate(ctx Context, inode Ino, flags uint8, length uint6
return err
}
m.parseAttr(a, &t)
if t.Typ != TypeFile || t.Flags&(FlagImmutable|FlagAppend) != 0 || t.Parent > TrashInode {
if t.Typ != TypeFile || t.Flags&(FlagImmutable|FlagAppend) != 0 || (flags == 0 && t.Parent > TrashInode) {
return syscall.EPERM
}
if !skipPermCheck {
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ func (m *dbMeta) doTruncate(ctx Context, inode Ino, flags uint8, length uint64,
if !ok {
return syscall.ENOENT
}
if nodeAttr.Type != TypeFile || nodeAttr.Flags&(FlagImmutable|FlagAppend) != 0 || nodeAttr.Parent > TrashInode {
if nodeAttr.Type != TypeFile || nodeAttr.Flags&(FlagImmutable|FlagAppend) != 0 || (flags == 0 && nodeAttr.Parent > TrashInode) {
return syscall.EPERM
}
m.parseAttr(&nodeAttr, attr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ func (m *kvMeta) doTruncate(ctx Context, inode Ino, flags uint8, length uint64,
}
t := Attr{}
m.parseAttr(a, &t)
if t.Typ != TypeFile || t.Flags&(FlagImmutable|t.Flags&FlagAppend) != 0 || t.Parent > TrashInode {
if t.Typ != TypeFile || t.Flags&(FlagImmutable|t.Flags&FlagAppend) != 0 || (flags == 0 && t.Parent > TrashInode) {
return syscall.EPERM
}
if !skipPermCheck {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func (v *VFS) Truncate(ctx Context, ino Ino, size int64, fh uint64, attr *Attr)
err = syscall.EACCES
return
}
err = v.Meta.Truncate(ctx, ino, 0, uint64(size), attr, true)
err = v.Meta.Truncate(ctx, ino, 1, uint64(size), attr, true)
}
if err == 0 {
v.writer.Truncate(ino, uint64(size))
Expand Down
5 changes: 3 additions & 2 deletions pkg/vfs/vfs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ func (v *VFS) SetAttr(ctx Context, ino Ino, set int, fh uint64, mode, uid, gid u
v.writer.UpdateMtime(ino, time.Now())
}
}

err = v.Meta.SetAttr(ctx, ino, uint16(set), 0, attr)
if (set & (meta.SetAttrMode | meta.SetAttrUID | meta.SetAttrGID | meta.SetAttrAtime | meta.SetAttrMtime | meta.SetAttrMtimeNow)) != 0 {
err = v.Meta.SetAttr(ctx, ino, uint16(set), 0, attr)
}
if err == 0 {
v.UpdateLength(ino, attr)
entry = &meta.Entry{Inode: ino, Attr: attr}
Expand Down

0 comments on commit 9a11446

Please sign in to comment.