mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
mount: able to trim a file
This commit is contained in:
parent
1b0bfbaf59
commit
630f72f8c5
|
@ -102,9 +102,18 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
|
||||||
if req.Valid.Size() {
|
if req.Valid.Size() {
|
||||||
|
|
||||||
glog.V(3).Infof("%v file setattr set size=%v", file.fullpath(), req.Size)
|
glog.V(3).Infof("%v file setattr set size=%v", file.fullpath(), req.Size)
|
||||||
if req.Size == 0 {
|
if req.Size < filer2.TotalSize(file.entry.Chunks) {
|
||||||
// fmt.Printf("truncate %v \n", fullPath)
|
// fmt.Printf("truncate %v \n", fullPath)
|
||||||
file.entry.Chunks = nil
|
var chunks []*filer_pb.FileChunk
|
||||||
|
for _, chunk := range file.entry.Chunks {
|
||||||
|
if uint64(chunk.Offset)+chunk.Size > req.Size {
|
||||||
|
chunk.Size = req.Size - uint64(chunk.Offset)
|
||||||
|
}
|
||||||
|
if chunk.Size > 0 {
|
||||||
|
chunks = append(chunks, chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.entry.Chunks = chunks
|
||||||
file.entryViewCache = nil
|
file.entryViewCache = nil
|
||||||
}
|
}
|
||||||
file.entry.Attributes.FileSize = req.Size
|
file.entry.Attributes.FileSize = req.Size
|
||||||
|
|
Loading…
Reference in a new issue