Example #1
0
func run(c *cli.Context) (err error) {
	// Mount, writing information about our progress to the writer that package
	// daemon gives us and telling it about the outcome.
	var mfs *fuse.MountedFileSystem
	{
		mountStatus := log.New(daemon.StatusWriter(), "", 0)
		mfs, err = mountFromContext(c, mountStatus)

		if err == nil {
			mountStatus.Println("File system has been successfully mounted.")
			daemon.SignalOutcome(nil)
		} else {
			err = fmt.Errorf("mountFromContext: %v", err)
			daemon.SignalOutcome(err)
			return
		}
	}

	// Let the user unmount with Ctrl-C (SIGINT).
	registerSIGINTHandler(mfs.Dir())

	// Wait for the file system to be unmounted.
	err = mfs.Join(context.Background())
	if err != nil {
		err = fmt.Errorf("MountedFileSystem.Join: %v", err)
		return
	}

	return
}
Example #2
0
// fuseMountFolder uses the fuseklient library to mount the given
// folder.
func (m *Mounter) fuseMountFolder(mount *Mount) error {
	var (
		t   transport.Transport
		err error
	)

	t, err = transport.NewRemoteTransport(m.Transport, fuseTellTimeout, mount.RemotePath)
	if err != nil {
		return err
	}

	// user specifies to prefetch all content upfront
	if mount.PrefetchAll {
		dt, err := transport.NewDiskTransport(mount.CachePath)
		if err != nil {
			return err
		}

		// cast into RemoteTransport for NewDualTransport
		rt := t.(*transport.RemoteTransport)

		t = transport.NewDualTransport(rt, dt)
	}

	cf := &fuseklient.Config{
		Path:           mount.LocalPath,
		MountName:      mount.MountName,
		NoIgnore:       mount.NoIgnore,
		NoPrefetchMeta: mount.NoPrefetchMeta,
		NoWatch:        mount.NoWatch,
		Trace:          mount.Trace,
	}

	f, err := fuseklient.New(t, cf)
	if isRemotePathError(err) {
		return ErrRemotePathDoesNotExist
	} else if err != nil {
		return err
	}

	mount.MountedFS = f
	mount.Unmounter = f

	var fs *fuse.MountedFileSystem
	if fs, err = f.Mount(); err != nil {
		return err
	}

	// TODO: what context to use?
	go fs.Join(context.TODO())

	return nil
}
Example #3
0
File: main.go Project: zfo/gcsfuse
func runCLIApp(c *cli.Context) (err error) {
	flags := populateFlags(c)

	// Extract arguments.
	if len(c.Args()) != 2 {
		err = fmt.Errorf(
			"%s takes exactly two arguments. Run `%s --help` for more info.",
			path.Base(os.Args[0]),
			path.Base(os.Args[0]))

		return
	}

	bucketName := c.Args()[0]
	mountPoint := c.Args()[1]

	// Canonicalize the mount point, making it absolute. This is important when
	// daemonizing below, since the daemon will change its working directory
	// before running this code again.
	mountPoint, err = filepath.Abs(mountPoint)
	if err != nil {
		err = fmt.Errorf("canonicalizing mount point: %v", err)
		return
	}

	fmt.Fprintf(os.Stderr, "Using mount point: %s\n", mountPoint)

	// If we haven't been asked to run in foreground mode, we should run a daemon
	// with the foreground flag set and wait for it to mount.
	if !flags.Foreground {
		// Find the executable.
		var path string
		path, err = osext.Executable()
		if err != nil {
			err = fmt.Errorf("osext.Executable: %v", err)
			return
		}

		// Set up arguments. Be sure to use foreground mode, and to send along the
		// potentially-modified mount point.
		args := append([]string{"--foreground"}, os.Args[1:]...)
		args[len(args)-1] = mountPoint

		// Pass along PATH so that the daemon can find fusermount on Linux.
		env := []string{
			fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
		}

		// Run.
		err = daemonize.Run(path, args, env, os.Stderr)
		if err != nil {
			err = fmt.Errorf("daemonize.Run: %v", err)
			return
		}

		return
	}

	// Mount, writing information about our progress to the writer that package
	// daemonize gives us and telling it about the outcome.
	var mfs *fuse.MountedFileSystem
	{
		mountStatus := log.New(daemonize.StatusWriter, "", 0)
		mfs, err = mountWithArgs(bucketName, mountPoint, flags, mountStatus)

		if err == nil {
			mountStatus.Println("File system has been successfully mounted.")
			daemonize.SignalOutcome(nil)
		} else {
			err = fmt.Errorf("mountWithArgs: %v", err)
			daemonize.SignalOutcome(err)
			return
		}
	}

	// Let the user unmount with Ctrl-C (SIGINT).
	registerSIGINTHandler(mfs.Dir())

	// Wait for the file system to be unmounted.
	err = mfs.Join(context.Background())
	if err != nil {
		err = fmt.Errorf("MountedFileSystem.Join: %v", err)
		return
	}

	return
}
Example #4
0
func main() {
	app := NewApp()
	app.Action = func(c *cli.Context) (err error) {
		// We should get two arguments exactly. Otherwise error out.
		if len(c.Args()) != 2 {
			fmt.Fprintf(
				os.Stderr,
				"Error: %s takes exactly two arguments.\n\n",
				app.Name)
			cli.ShowAppHelp(c)
			os.Exit(1)
		}

		// Populate and parse flags.
		bucketName := c.Args()[0]
		mountPoint := c.Args()[1]
		flags := PopulateFlags(c)

		InitLoggers(!flags.Foreground)

		massagePath()

		if !flags.Foreground {
			massageArg0()

			ctx := new(daemon.Context)
			var child *os.Process
			child, err = ctx.Reborn()

			if err != nil {
				panic(fmt.Sprintf("unable to daemonize: %v", err))
			}

			if child != nil {
				return
			} else {
				defer ctx.Release()
			}

		}

		// Mount the file system.
		var mfs *fuse.MountedFileSystem
		mfs, err = mount(
			context.Background(),
			bucketName,
			mountPoint,
			flags)

		if err != nil {
			log.Fatalf("Mounting file system: %v", err)
		}

		log.Println("File system has been successfully mounted.")

		// Let the user unmount with Ctrl-C (SIGINT).
		registerSIGINTHandler(mfs.Dir())

		// Wait for the file system to be unmounted.
		err = mfs.Join(context.Background())
		if err != nil {
			err = fmt.Errorf("MountedFileSystem.Join: %v", err)
			return
		}

		log.Println("Successfully exiting.")
		return
	}

	err := app.Run(MassageMountFlags(os.Args))
	if err != nil {
		log.Fatalln(err)
	}
}