NewMountCommand makes a mount command with the given name and Mount function
(commandName string, hidden bool, mount MountFn)
| 273 | |
| 274 | // NewMountCommand makes a mount command with the given name and Mount function |
| 275 | func 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 | } |
no test coverage detected
searching dependent graphs…