Added FUSE support #55

Merged
Elara6331 merged 65 commits from yannickulrich/itd:fuse into master 2023-03-25 22:23:52 +00:00
Showing only changes of commit fe43a608d0 - Show all commits

33
fuse.go
View File

@ -10,6 +10,8 @@ import (
"github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"strconv" "strconv"
"io"
"bytes"
) )
type Device struct { type Device struct {
@ -266,8 +268,17 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
log.Error("Flush failed: create").Str("path", fh.path).Err(err).Send() log.Error("Flush failed: create").Str("path", fh.path).Err(err).Send()
return syscall.EROFS return syscall.EROFS
} }
nread, err := fp.Write(fh.content)
if err != nil || nread != len(fh.content) { go func() {
// For every progress event
for sent := range fp.Progress() {
log.Info("Progress").Int("bytes", int(sent)).Int("of", len(fh.content)).Send();
}
}()
r := bytes.NewReader(fh.content)
nread, err := io.Copy(fp, r)
if err != nil {
log.Error("Flush failed: write").Str("path", fh.path).Err(err).Send() log.Error("Flush failed: write").Str("path", fh.path).Err(err).Send()
fp.Close() fp.Close()
return syscall.EROFS return syscall.EROFS
@ -337,16 +348,24 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
defer fp.Close() defer fp.Close()
buf := make([]byte, f.self.size); b := &bytes.Buffer{}
nread, err := fp.Read(buf)
if err != nil || nread != int(f.self.size) { go func() {
log.Error("Reading file failed").Str("path", f.path).Err(err).Send(); // For every progress event
for sent := range fp.Progress() {
log.Info("Progress").Int("bytes", int(sent)).Int("of", int(f.self.size)).Send();
}
}()
_, err = io.Copy(b, fp)
if err != nil {
log.Error("Read failed").Str("path", f.path).Err(err).Send()
fp.Close() fp.Close()
return nil, 0, syscall.EROFS return nil, 0, syscall.EROFS
} }
fh = &bytesFileReadHandle{ fh = &bytesFileReadHandle{
content: buf, content: b.Bytes(),
} }
return fh, fuse.FOPEN_DIRECT_IO, 0 return fh, fuse.FOPEN_DIRECT_IO, 0
} }