Skip to content

Commit

Permalink
cmd mountlib: adding remount option for linux systems - fixes #6488
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Reynolds authored and KDreynolds committed May 14, 2024
1 parent 29ed17d commit 75bc67f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cmd/mountlib/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -59,6 +60,7 @@ type Options struct {
NetworkMode bool // Windows only
DirectIO bool // use Direct IO for file access
CaseInsensitive fs.Tristate
Remount bool
}

// DefaultOpt is the default values for creating the mount
Expand Down Expand Up @@ -158,9 +160,11 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.BoolVarP(flagSet, &Opt.NoAppleDouble, "noappledouble", "", Opt.NoAppleDouble, "Ignore Apple Double (._) and .DS_Store files (supported on OSX only)", "Mount")
flags.BoolVarP(flagSet, &Opt.NoAppleXattr, "noapplexattr", "", Opt.NoAppleXattr, "Ignore all \"com.apple.*\" extended attributes (supported on OSX only)", "Mount")
// Windows only
flags.BoolVarP(flagSet, &Opt.NetworkMode, "network-mode", "", Opt.NetworkMode, "Mount as remote network drive, instead of fixed disk drive (supported on Windows only)", "Mount")
// Unix only
flags.DurationVarP(flagSet, &Opt.DaemonWait, "daemon-wait", "", Opt.DaemonWait, "Time to wait for ready mount from daemon (maximum time on Linux, constant sleep time on OSX/BSD) (not supported on Windows)", "Mount")
flags.BoolVarP(flagSet, &Opt.NetworkMode, "network--mode", "", Opt.NetworkMode, "Mount as remote network drive, instead of fixed disk drive (supported on Windows only)", "Mount")
// Linux specific
if runtime.GOOS == "linux" {
flags.BoolVarP(flagSet, &Opt.Remount, "remount", "", false, "Remount a file system")

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / android-all

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / linux

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / linux_386

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / mac_amd64

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / mac_arm64

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / windows

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / other_os

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / go1.20

not enough arguments in call to flags.BoolVarP

Check failure on line 166 in cmd/mountlib/mount.go

View workflow job for this annotation

GitHub Actions / go1.21

not enough arguments in call to flags.BoolVarP
}
}

const (
Expand Down Expand Up @@ -283,11 +287,21 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm

// Mount the remote at mountpoint
func (m *MountPoint) Mount() (mountDaemon *os.Process, err error) {

// Ensure sensible defaults
m.SetVolumeName(m.MountOpt.VolumeName)
m.SetDeviceName(m.MountOpt.DeviceName)

// Handle the --remount flag by attempting to unmount the mountpoint first
if runtime.GOOS == "linux" && m.MountOpt.Remount {
// Remount option only works on linux.
unmountCmd := exec.Command("fusermount", "-uz", m.MountPoint)
if err := unmountCmd.Run(); err != nil {
log.Printf("Failed to unmount existing mount point %q: %v", m.MountPoint, err)
return nil, err
}
log.Printf("Successfully unmounted %q for remounting", m.MountPoint)
}

// Start background task if --daemon is specified
if m.MountOpt.Daemon {
mountDaemon, err = daemonize.StartDaemon(os.Args)
Expand Down
9 changes: 9 additions & 0 deletions docs/content/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ Flags used for `rclone check`.
```


## Mount

Flags specifically used for mounting operations with rclone.

```
--remount Attempt to remount an already-mounted filesystem. This is useful for changing mount flags without unmounting. Supported only on Linux.
```


## Networking

General networking and HTTP stuff.
Expand Down

0 comments on commit 75bc67f

Please sign in to comment.