Skip to content

Commit 6eee5f2

Browse files
committed
main: detect fusermount3 and don't add nonempty
fusermount3 (i.e. fusermount from libfuse 3.x) has dropped the `nonempty` option. Detect fusermount3 and don't add `nonempty` in this case. Fixes #440
1 parent 7dda236 commit 6eee5f2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

mount.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"log"
@@ -362,7 +363,9 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server {
362363
tlog.Info.Printf(tlog.ColorYellow + "THE OPTION \"-forcedecode\" IS ACTIVE. GOCRYPTFS WILL RETURN CORRUPT DATA!" +
363364
tlog.ColorReset)
364365
}
365-
if args.nonempty {
366+
// fusermount from libfuse 3.x removed the "nonempty" option and exits
367+
// with an error if it sees it. Only add it to the options on libfuse 2.x.
368+
if args.nonempty && haveFusermount2() {
366369
mOpts.Options = append(mOpts.Options, "nonempty")
367370
}
368371
// Set values shown in "df -T" and friends
@@ -436,6 +439,25 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server {
436439
return srv
437440
}
438441

442+
// haveFusermount2 finds out if the "fusermount" binary is from libfuse 2.x.
443+
func haveFusermount2() bool {
444+
cmd := exec.Command("/bin/fusermount", "-V")
445+
var out bytes.Buffer
446+
cmd.Stdout = &out
447+
err := cmd.Run()
448+
if err != nil {
449+
tlog.Warn.Printf("warning: haveFusermount2: %v", err)
450+
return false
451+
}
452+
// libfuse 2: fusermount version: 2.9.9
453+
// libfuse 3: fusermount3 version: 3.9.0
454+
v := out.String()
455+
if strings.HasPrefix(v, "fusermount version") {
456+
return true
457+
}
458+
return false
459+
}
460+
439461
func handleSigint(srv *fuse.Server, mountpoint string) {
440462
ch := make(chan os.Signal, 1)
441463
signal.Notify(ch, os.Interrupt)

0 commit comments

Comments
 (0)