Пример #1
0
Файл: ls.go Проект: bosky101/mc
// doList - list all entities inside a folder
func doList(clnt client.Client, recursive bool) error {
	var err error
	for contentCh := range clnt.List(recursive) {
		if contentCh.Err != nil {
			switch err := iodine.ToError(contentCh.Err).(type) {
			// handle this specifically for filesystem
			case client.ISBrokenSymlink:
				console.Errors(ErrorMessage{
					Message: "Failed with",
					Error:   iodine.New(err, nil),
				})
				continue
			}
			if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
				console.Errors(ErrorMessage{
					Message: "Failed with",
					Error:   iodine.New(contentCh.Err, nil),
				})
				continue
			}
			err = contentCh.Err
			break
		}
		console.Prints(parseContent(contentCh.Content))
	}
	if err != nil {
		return iodine.New(err, map[string]string{"Target": clnt.URL().String()})
	}
	return nil
}
Пример #2
0
func sessionExecute(bar barSend, s *sessionV1) {
	switch s.CommandType {
	case "cp":
		for cps := range doCopyCmdSession(bar, s) {
			if cps.Error != nil {
				console.Errors(ErrorMessage{
					Message: "Failed with",
					Error:   iodine.New(cps.Error, nil),
				})
			}
			if cps.Done {
				if err := saveSession(s); err != nil {
					console.Fatals(ErrorMessage{
						Message: "Failed with",
						Error:   iodine.New(err, nil),
					})
				}
				console.Println()
				console.Infos(InfoMessage{
					Message: "Session terminated. To resume session type ‘mc session resume " + s.SessionID + "’",
				})
				// this os.Exit is needed really to exit in-case of "os.Interrupt"
				os.Exit(0)
			}
		}
	case "sync":
		for ss := range doSyncCmdSession(bar, s) {
			if ss.Error != nil {
				console.Errors(ErrorMessage{
					Message: "Failed with",
					Error:   iodine.New(ss.Error, nil),
				})
			}
			if ss.Done {
				if err := saveSession(s); err != nil {
					console.Fatals(ErrorMessage{
						Message: "Failed with",
						Error:   iodine.New(err, nil),
					})
				}
				console.Println()
				console.Infos(InfoMessage{
					Message: "Session terminated. To resume session type ‘mc session resume " + s.SessionID + "’",
				})
				// this os.Exit is needed really to exit in-case of "os.Interrupt"
				os.Exit(0)
			}
		}
	}
}
Пример #3
0
func runAccessCmd(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
	}
	if !isMcConfigExists() {
		console.Fatals(ErrorMessage{
			Message: "Please run \"mc config generate\"",
			Error:   iodine.New(errNotConfigured{}, nil),
		})
	}
	config, err := getMcConfig()
	if err != nil {
		console.Fatals(ErrorMessage{
			Message: "loading config file failed",
			Error:   iodine.New(err, nil),
		})
	}
	acl := bucketACL(ctx.Args().First())
	if !acl.isValidBucketACL() {
		console.Fatals(ErrorMessage{
			Message: "Valid types are [private, public, readonly].",
			Error:   iodine.New(errInvalidACL{acl: acl.String()}, nil),
		})
	}
	for _, arg := range ctx.Args().Tail() {
		targetURL, err := getExpandedURL(arg, config.Aliases)
		if err != nil {
			switch e := iodine.ToError(err).(type) {
			case errUnsupportedScheme:
				console.Fatals(ErrorMessage{
					Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
					Error:   iodine.New(e, nil),
				})
			default:
				console.Fatals(ErrorMessage{
					Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
					Error:   iodine.New(err, nil),
				})
			}
		}
		msg, err := doUpdateAccessCmd(targetURL, acl)
		if err != nil {
			console.Errors(ErrorMessage{
				Message: msg,
				Error:   iodine.New(err, nil),
			})
		}
		console.Infos(InfoMessage{
			Message: msg,
		})
	}
}
Пример #4
0
// runMakeBucketCmd is the handler for mc mb command
func runMakeBucketCmd(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
	}
	if !isMcConfigExists() {
		console.Fatals(ErrorMessage{
			Message: "Please run \"mc config generate\"",
			Error:   iodine.New(errNotConfigured{}, nil),
		})
	}
	config, err := getMcConfig()
	if err != nil {
		console.Fatals(ErrorMessage{
			Message: "Unable to read config file ‘" + mustGetMcConfigPath() + "’",
			Error:   iodine.New(err, nil),
		})
	}
	for _, arg := range ctx.Args() {
		targetURL, err := getExpandedURL(arg, config.Aliases)
		if err != nil {
			switch e := iodine.ToError(err).(type) {
			case errUnsupportedScheme:
				console.Fatals(ErrorMessage{
					Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
					Error:   iodine.New(e, nil),
				})
			default:
				console.Fatals(ErrorMessage{
					Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
					Error:   iodine.New(err, nil),
				})
			}
		}
		msg, err := doMakeBucketCmd(targetURL)
		if err != nil {
			console.Errors(ErrorMessage{
				Message: msg,
				Error:   iodine.New(err, nil),
			})
		}
		console.Infos(InfoMessage{
			Message: msg,
		})
	}
}
Пример #5
0
func runSyncCmd(ctx *cli.Context) {
	if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code
	}

	if !isMcConfigExists() {
		console.Fatals(ErrorMessage{
			Message: "Please run \"mc config generate\"",
			Error:   iodine.New(errNotConfigured{}, nil),
		})
	}

	if !isSessionDirExists() {
		if err := createSessionDir(); err != nil {
			console.Fatals(ErrorMessage{
				Message: "Failed with",
				Error:   iodine.New(err, nil),
			})
		}
	}

	s, err := newSession()
	if err != nil {
		console.Fatals(ErrorMessage{
			Message: "Failed with",
			Error:   iodine.New(err, nil),
		})
	}
	s.CommandType = "sync"
	s.RootPath, _ = os.Getwd()

	// extract URLs.
	s.URLs, err = args2URLs(ctx.Args())
	if err != nil {
		console.Fatals(ErrorMessage{
			Message: fmt.Sprintf("Unknown URL types found: ‘%s’", ctx.Args()),
			Error:   iodine.New(err, nil),
		})
	}

	var bar barSend
	// set up progress bar
	if !globalQuietFlag {
		bar = newCpBar()
	}

	for ss := range doSyncCmdSession(bar, s) {
		if ss.Error != nil {
			console.Errors(ErrorMessage{
				Message: "Failed with",
				Error:   iodine.New(ss.Error, nil),
			})
		}
		if ss.Done {
			if err := saveSession(s); err != nil {
				console.Fatals(ErrorMessage{
					Message: "Failed wtih",
					Error:   iodine.New(err, nil),
				})
			}
			console.Println()
			console.Infos(InfoMessage{
				Message: "Session terminated. To resume session type ‘mc session resume " + s.SessionID + "’",
			})
			// this os.Exit is needed really to exit in-case of "os.Interrupt"
			os.Exit(0)
		}
	}

	if !globalQuietFlag {
		bar.Finish()
		// ignore any error returned here
		clearSession(s.SessionID)
	}
}