mirror of
https://github.com/octoleo/restic.git
synced 2024-11-05 04:47:51 +00:00
Merge pull request #554 from restic/debug-fuse-panic
Fix fuse panic with empty files
This commit is contained in:
commit
959df5cc14
@ -4,6 +4,7 @@
|
|||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"restic"
|
"restic"
|
||||||
@ -120,9 +121,21 @@ func (f *file) getBlobAt(i int) (blob []byte, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
||||||
debug.Log("file.Read", "Read(%v), file size %v", req.Size, f.node.Size)
|
debug.Log("file.Read", "Read(%v, %v, %v), file size %v", f.node.Name, req.Size, req.Offset, f.node.Size)
|
||||||
offset := req.Offset
|
offset := req.Offset
|
||||||
|
|
||||||
|
if uint64(offset) > f.node.Size {
|
||||||
|
debug.Log("file.Read", "Read(%v): offset is greater than file size: %v > %v",
|
||||||
|
f.node.Name, req.Offset, f.node.Size)
|
||||||
|
return errors.New("offset greater than files size")
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle special case: file is empty
|
||||||
|
if f.node.Size == 0 {
|
||||||
|
resp.Data = resp.Data[:0]
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Skip blobs before the offset
|
// Skip blobs before the offset
|
||||||
startContent := 0
|
startContent := 0
|
||||||
for offset > int64(f.sizes[startContent]) {
|
for offset > int64(f.sizes[startContent]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user