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 https://github.com/rfjakob/gocryptfs/pull/440
This commit is contained in:
Jakob Unterwurzacher 2019-12-28 20:44:12 +01:00
parent 1364b44ae3
commit db43bfc4c0
1 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
@ -362,7 +363,9 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server {
tlog.Info.Printf(tlog.ColorYellow + "THE OPTION \"-forcedecode\" IS ACTIVE. GOCRYPTFS WILL RETURN CORRUPT DATA!" +
tlog.ColorReset)
}
if args.nonempty {
// fusermount from libfuse 3.x removed the "nonempty" option and exits
// with an error if it sees it. Only add it to the options on libfuse 2.x.
if args.nonempty && haveFusermount2() {
mOpts.Options = append(mOpts.Options, "nonempty")
}
// Set values shown in "df -T" and friends
@ -436,6 +439,25 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server {
return srv
}
// haveFusermount2 finds out if the "fusermount" binary is from libfuse 2.x.
func haveFusermount2() bool {
cmd := exec.Command("/bin/fusermount", "-V")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
tlog.Warn.Printf("warning: haveFusermount2: %v", err)
return false
}
// libfuse 2: fusermount version: 2.9.9
// libfuse 3: fusermount3 version: 3.9.0
v := out.String()
if strings.HasPrefix(v, "fusermount version") {
return true
}
return false
}
func handleSigint(srv *fuse.Server, mountpoint string) {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)