Added FUSE support #55
							
								
								
									
										33
									
								
								fuse.go
									
									
									
									
									
								
							
							
						
						@@ -10,6 +10,8 @@ import (
 | 
			
		||||
	"github.com/hanwen/go-fuse/v2/fs"
 | 
			
		||||
	"github.com/hanwen/go-fuse/v2/fuse"
 | 
			
		||||
	"strconv"
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					yannickulrich marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				 | 
			||||
	"io"
 | 
			
		||||
	"bytes"
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					yannickulrich marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						Elara6331
						commented  
			
		Use  Use `os.MkdirAll` here instead so that it creates parent directories, and handle the error (just return it). 
			
			
		
				
					
						yannickulrich
						commented  
			
		This is actually a bit more complicated than that. If the mountpoint already exists, fuse will crash. We also can't delete the mountpoint beforehand ( This is actually a bit more complicated than that. If the mountpoint already exists, fuse will crash. We also can't delete the mountpoint beforehand (`rm: cannot remove '/tmp/itd/mnt': Transport endpoint is not connected`). The best way to solve this should be calling the [unmount function](https://pkg.go.dev/github.com/hanwen/go-fuse/v2@v2.2.0/fuse#Server.Unmount). How would you suggest going about doing this? 
			
			
		
				
					
						Elara6331
						commented  
			
		Yeah, this one is going to be a bit more complicated. The FUSE library does have a different unmount function that you could call before trying to mount the fs, but it's not exported, so we'll need to do a small hack to get access to it anyway. In the  
 | 
			||||
)
 | 
			
		||||
 | 
			
		||||
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()
 | 
			
		||||
		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()
 | 
			
		||||
		fp.Close()
 | 
			
		||||
		return syscall.EROFS
 | 
			
		||||
@@ -337,16 +348,24 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
 | 
			
		||||
 | 
			
		||||
			defer fp.Close()
 | 
			
		||||
 | 
			
		||||
			buf := make([]byte, f.self.size);
 | 
			
		||||
			nread, err := fp.Read(buf)
 | 
			
		||||
			if err != nil || nread != int(f.self.size) {
 | 
			
		||||
				log.Error("Reading file failed").Str("path", f.path).Err(err).Send();
 | 
			
		||||
			b := &bytes.Buffer{}
 | 
			
		||||
 | 
			
		||||
			go func() {
 | 
			
		||||
				// 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()
 | 
			
		||||
				return nil, 0, syscall.EROFS
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			fh = &bytesFileReadHandle{
 | 
			
		||||
				content: buf,
 | 
			
		||||
				content: b.Bytes(),
 | 
			
		||||
			}
 | 
			
		||||
			return fh, fuse.FOPEN_DIRECT_IO, 0
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
This function should be called
startFUSEinstead to adhere to Go naming conventionsThanks, I'm relatively new to Go, sorry for these issues
Done in
673383f