Mount is non-blocking again

This commit is contained in:
Caleb Gardner
2023-01-04 06:01:12 -06:00
parent f2d86aff96
commit 658e5c9e0b
2 changed files with 11 additions and 7 deletions
+10 -7
View File
@@ -11,10 +11,8 @@ import (
"github.com/CalebQ42/squashfs/internal/inode"
)
// Mounts the archive to the given mountpoint using fuse3.
// Blocks until the arhive is unmounted.
// Hightly suggested to run in a goroutine.
// Will take a moment before MountWait and Unmount will work correctly.
// Mounts the archive to the given mountpoint using fuse3. Non-blocking.
// If Unmount does not get called, the mount point must be unmounted using umount before the directory can be used again.
func (r *Reader) Mount(mountpoint string) (err error) {
if r.con != nil {
return errors.New("squashfs archive already mounted")
@@ -23,14 +21,19 @@ func (r *Reader) Mount(mountpoint string) (err error) {
if err != nil {
return
}
err = fs.Serve(r.con, &squashFuse{r: r})
<-r.con.Ready
r.mountDone = make(chan struct{})
go func() {
fs.Serve(r.con, &squashFuse{r: r})
close(r.mountDone)
}()
return
}
// Blocks until the mount ends.
func (r *Reader) MountWait() {
if r.con != nil {
<-r.con.Ready
if r.mountDone != nil {
<-r.mountDone
}
}
+1
View File
@@ -18,6 +18,7 @@ import (
type Reader struct {
*FS
con *fuse.Conn
mountDone chan struct{}
d decompress.Decompressor
r io.ReaderAt
fragEntries []fragEntry