提交 90a3252d 作者: Jeromy

fix append bug and overwrite/truncate bug

an alternative fix to the truncate/append problem

Update ipns_unix.go
上级 ee3c3070
...@@ -337,6 +337,20 @@ func (fi *File) Flush(ctx context.Context, req *fuse.FlushRequest) error { ...@@ -337,6 +337,20 @@ func (fi *File) Flush(ctx context.Context, req *fuse.FlushRequest) error {
} }
} }
func (fi *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
cursize, err := fi.fi.Size()
if err != nil {
return err
}
if cursize != int64(req.Size) {
err := fi.fi.Truncate(int64(req.Size))
if err != nil {
return err
}
}
return nil
}
// Fsync flushes the content in the file to disk, but does not // Fsync flushes the content in the file to disk, but does not
// update the dag tree internally // update the dag tree internally
func (fi *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { func (fi *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
...@@ -370,13 +384,21 @@ func (dir *Directory) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Nod ...@@ -370,13 +384,21 @@ func (dir *Directory) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Nod
func (fi *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) { func (fi *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
if req.Flags&fuse.OpenTruncate != 0 { if req.Flags&fuse.OpenTruncate != 0 {
log.Warning("Need to truncate file!") log.Info("Need to truncate file!")
err := fi.fi.Truncate(0) err := fi.fi.Truncate(0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else if req.Flags&fuse.OpenAppend != 0 { } else if req.Flags&fuse.OpenAppend != 0 {
log.Warning("Need to append to file!") log.Info("Need to append to file!")
// seek(0) essentially resets the file object, this is required for appends to work
// properly
_, err := fi.fi.Seek(0, os.SEEK_SET)
if err != nil {
log.Error("seek reset failed: ", err)
return nil, err
}
} }
return fi, nil return fi, nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论