Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd mountlib: adding remount option for linux systems - fixes #6488 #7802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 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 @@ -139,8 +141,7 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.DurationVarP(flagSet, &Opt.AttrTimeout, "attr-timeout", "", Opt.AttrTimeout, "Time for which file/directory attributes are cached", "Mount")
flags.StringArrayVarP(flagSet, &Opt.ExtraOptions, "option", "o", []string{}, "Option for libfuse/WinFsp (repeat if required)", "Mount")
flags.StringArrayVarP(flagSet, &Opt.ExtraFlags, "fuse-flag", "", []string{}, "Flags or arguments to be passed direct to libfuse/WinFsp (repeat if required)", "Mount")
// Non-Windows only
flags.BoolVarP(flagSet, &Opt.Daemon, "daemon", "", Opt.Daemon, "Run mount in background and exit parent process (as background output is suppressed, use --log-file with --log-format=pid,... to monitor) (not supported on Windows)", "Mount")
flags.BoolVarP(flagSet, &Opt.Daemon, "daemon", "", Opt.Daemon, "Run mount in background and exit parent process (as background output is suppressed, use --log-file with --log-format=pid,... to monitor)", "Mount")
flags.DurationVarP(flagSet, &Opt.DaemonTimeout, "daemon-timeout", "", Opt.DaemonTimeout, "Time limit for rclone to respond to kernel (not supported on Windows)", "Mount")
flags.BoolVarP(flagSet, &Opt.DefaultPermissions, "default-permissions", "", Opt.DefaultPermissions, "Makes kernel enforce access control based on the file mode (not supported on Windows)", "Mount")
flags.BoolVarP(flagSet, &Opt.AllowNonEmpty, "allow-non-empty", "", Opt.AllowNonEmpty, "Allow mounting over a non-empty directory (not supported on Windows)", "Mount")
Expand All @@ -152,15 +153,14 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.StringVarP(flagSet, &Opt.DeviceName, "devname", "", Opt.DeviceName, "Set the device name - default is remote:path", "Mount")
flags.FVarP(flagSet, &Opt.CaseInsensitive, "mount-case-insensitive", "", "Tell the OS the mount is case insensitive (true) or sensitive (false) regardless of the backend (auto)", "Mount")
flags.BoolVarP(flagSet, &Opt.DirectIO, "direct-io", "", Opt.DirectIO, "Use Direct IO, disables caching of data", "Mount")
// Windows and OSX
flags.StringVarP(flagSet, &Opt.VolumeName, "volname", "", Opt.VolumeName, "Set the volume name (supported on Windows and OSX only)", "Mount")
// OSX only
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")
// Linux specific
if runtime.GOOS == "linux" {
flags.BoolVarP(flagSet, &Opt.Remount, "remount", "", false, "Remount a file system", "Mount")
}
}

const (
Expand Down Expand Up @@ -283,11 +283,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