From 62b76b631cabf0c73b394d44871bbb9bddb571c3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 24 Jun 2024 13:08:05 +0100 Subject: [PATCH] nfsmount: make the --sudo flag work for umount as well as mount --- cmd/nfsmount/nfsmount.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/nfsmount/nfsmount.go b/cmd/nfsmount/nfsmount.go index f172e1ca0..b21ffdd3e 100644 --- a/cmd/nfsmount/nfsmount.go +++ b/cmd/nfsmount/nfsmount.go @@ -32,7 +32,7 @@ func init() { cmd.Annotations["status"] = "Experimental" mountlib.AddRc(name, mount) cmdFlags := cmd.Flags() - flags.BoolVarP(cmdFlags, &sudo, "sudo", "", sudo, "Use sudo to run the mount command as root.", "") + flags.BoolVarP(cmdFlags, &sudo, "sudo", "", sudo, "Use sudo to run the mount/umount commands as root.", "") nfs.AddFlags(cmdFlags, &nfsServerOpt) } @@ -89,7 +89,12 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (asyncerrors if runtime.GOOS == "darwin" { out, umountErr = exec.Command("diskutil", "umount", "force", mountpoint).CombinedOutput() } else { - out, umountErr = exec.Command("umount", "-f", mountpoint).CombinedOutput() + cmd := []string{} + if sudo { + cmd = append(cmd, "sudo") + } + cmd = append(cmd, "umount", "-f", mountpoint) + out, umountErr = exec.Command(cmd[0], cmd[1:]...).CombinedOutput() } shutdownErr := s.Shutdown() VFS.Shutdown()