Пример #1
0
func ListFiles(client *server.Client, glob string) {

	var items []*vault.Item
	var err error
	err = prompt.NewProcess("Retriving file information ...", func() error {

		if glob != "" {
			items, err = client.Find(glob)
		} else {
			items, err = client.List()
		}

		return err
	})

	if err != nil {
		fmt.Printf("%v", err)
		os.Exit(1)
	}
	fmt.Printf("total %d\n", len(items))

	writer := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
	for _, i := range items {
		fmt.Fprintf(writer, "%s\t%s\t%s\t%s\n", humanize.Bytes(i.Size), i.Name, i.Mime, i.Id)

	}
	writer.Flush()

}
Пример #2
0
func mountCmd(client *server.Client, mountpoint string) {

	if !filepath.IsAbs(mountpoint) {

		abs, err := filepath.Abs(mountpoint)

		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			os.Exit(1)
		}

		mountpoint = abs
	}

	if _, err := os.Lstat(mountpoint); err != nil {
		fmt.Fprintf(os.Stderr, "mountpoint does not exists: %s", mountpoint)
		os.Exit(1)
	}

	m := mount.NewMount(client, mountpoint)

	done := make(chan bool, 1)
	defer close(done)
	go func() {
		err := m.Serve()

		if err != nil {
			fmt.Printf("%v\n", err)
		}
		done <- true
	}()

	cleanup := func() {
		err := prompt.NewProcess("Umounting "+mountpoint+" ...", func() error {
			return m.Close()
		})
		ret := 0
		if err != nil {
			fmt.Printf("%v\n", err)
			ret = 1
		}
		os.Exit(ret)
	}

	ch := make(chan os.Signal, 1)
	defer close(ch)
	signal.Notify(ch, os.Interrupt)
	signal.Notify(ch, syscall.SIGTERM)

	for {
		select {
		case <-done:
			cleanup()
		case <-ch:
			cleanup()
		default:
			// just move along
		}

	}

}