示例#1
0
文件: main.go 项目: zfo/gcsfuse
// Mount the file system according to arguments in the supplied context.
func mountWithArgs(
	bucketName string,
	mountPoint string,
	flags *flagStorage,
	mountStatus *log.Logger) (mfs *fuse.MountedFileSystem, err error) {
	// Enable invariant checking if requested.
	if flags.DebugInvariants {
		syncutil.EnableInvariantChecking()
	}

	// Grab the connection.
	mountStatus.Println("Opening GCS connection...")

	conn, err := getConn(flags)
	if err != nil {
		err = fmt.Errorf("getConn: %v", err)
		return
	}

	// Mount the file system.
	mfs, err = mountWithConn(
		context.Background(),
		bucketName,
		mountPoint,
		flags,
		conn,
		mountStatus)

	if err != nil {
		err = fmt.Errorf("mountWithConn: %v", err)
		return
	}

	return
}
示例#2
0
文件: main.go 项目: andrewgaul/goofys
func main() {
	// Make logging output better.
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)

	app := newApp()
	app.Action = func(c *cli.Context) {
		var 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)

		// Enable invariant checking if requested.
		if flags.DebugInvariants {
			syncutil.EnableInvariantChecking()
		}

		// Mount the file system.
		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.")
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatalln(err)
	}
}
示例#3
0
func TestMain(m *testing.M) {
	flag.Parse()

	if *fCheckInvariants {
		syncutil.EnableInvariantChecking()
	}

	os.Exit(m.Run())
}
示例#4
0
文件: main.go 项目: horzadome/gcsfuse
// Mount the file system according to arguments in the supplied context.
func mountFromContext(
	c *cli.Context,
	mountStatus *log.Logger) (mfs *fuse.MountedFileSystem, err error) {
	// Extract arguments.
	if len(c.Args()) != 2 {
		err = fmt.Errorf(
			"Error: %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]

	// Populate and parse flags.
	flags := populateFlags(c)

	// Enable invariant checking if requested.
	if flags.DebugInvariants {
		syncutil.EnableInvariantChecking()
	}

	// Grab the connection.
	mountStatus.Println("Opening GCS connection...")

	conn, err := getConn(flags)
	if err != nil {
		err = fmt.Errorf("getConn: %v", err)
		return
	}

	// Mount the file system.
	mfs, err = mount(
		context.Background(),
		bucketName,
		mountPoint,
		flags,
		conn,
		mountStatus)

	if err != nil {
		err = fmt.Errorf("mount: %v", err)
		return
	}

	return
}