MCPcopy
hub / github.com/rclone/rclone / NewMountCommand

Function NewMountCommand

cmd/mountlib/mount.go:275–359  ·  view source on GitHub ↗

NewMountCommand makes a mount command with the given name and Mount function

(commandName string, hidden bool, mount MountFn)

Source from the content-addressed store, hash-verified

273
274// NewMountCommand makes a mount command with the given name and Mount function
275func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Command {
276 var commandDefinition = &cobra.Command{
277 Use: commandName + " remote:path /path/to/mountpoint",
278 Hidden: hidden,
279 Short: `Mount the remote as file system on a mountpoint.`,
280 Long: help(commandName) + strings.TrimSpace(vfs.Help()),
281 Annotations: map[string]string{
282 "versionIntroduced": "v1.33",
283 "groups": "Filter",
284 },
285 Run: func(command *cobra.Command, args []string) {
286 cmd.CheckArgs(2, 2, command, args)
287
288 if fs.GetConfig(context.Background()).UseListR {
289 fs.Logf(nil, "--fast-list does nothing on a mount")
290 }
291
292 if Opt.Daemon {
293 config.PassConfigKeyForDaemonization = true
294 }
295
296 if os.Getenv("PATH") == "" && runtime.GOOS != "windows" {
297 // PATH can be unset when running under Autofs or Systemd mount
298 fs.Debugf(nil, "Using fallback PATH to run fusermount")
299 _ = os.Setenv("PATH", "/bin:/usr/bin")
300 }
301
302 // Show stats if the user has specifically requested them
303 if cmd.ShowStats() {
304 defer cmd.StartStats()()
305 }
306
307 mnt := NewMountPoint(mount, args[1], cmd.NewFsDir(args), &Opt, &vfscommon.Opt)
308 mountDaemon, err := mnt.Mount()
309
310 // Wait for foreground mount, if any...
311 if mountDaemon == nil {
312 if err == nil {
313 defer systemd.Notify()()
314 err = mnt.Wait()
315 }
316 if err != nil {
317 fs.Fatalf(nil, "Fatal error: %v", err)
318 }
319 return
320 }
321
322 // Wait for mountDaemon, if any...
323 killOnce := sync.Once{}
324 killDaemon := func(reason string) {
325 killOnce.Do(func() {
326 if err := mountDaemon.Signal(os.Interrupt); err != nil {
327 fs.Errorf(nil, "%s. Failed to terminate daemon pid %d: %v", reason, mountDaemon.Pid, err)
328 return
329 }
330 fs.Debugf(nil, "%s. Terminating daemon pid %d", reason, mountDaemon.Pid)
331 })
332 }

Callers 5

initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92

Calls 15

MountMethod · 0.95
WaitMethod · 0.95
HelpFunction · 0.92
CheckArgsFunction · 0.92
GetConfigFunction · 0.92
LogfFunction · 0.92
DebugfFunction · 0.92
ShowStatsFunction · 0.92
StartStatsFunction · 0.92
NewFsDirFunction · 0.92
NotifyFunction · 0.92
FatalfFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…