예제 #1
0
파일: download.go 프로젝트: 40a/cbfs
func downloadCommand(u string, args []string) {
	src := dlFlags.Arg(0)
	destbase := dlFlags.Arg(1)

	if destbase == "" {
		destbase = filepath.Base(src)
	}

	for len(src) > 0 && src[0] == '/' {
		src = src[1:]
	}

	httputil.InitHTTPTracker(false)

	client, err := cbfsclient.New(u)
	cbfstool.MaybeFatal(err, "Can't build a client: %v", err)

	things, err := client.ListDepth(src, 4096)
	cbfstool.MaybeFatal(err, "Can't list things: %v", err)

	start := time.Now()
	oids := []string{}
	dests := map[string][]string{}
	for fn, inf := range things.Files {
		fn = fn[len(src):]
		dests[inf.OID] = append(dests[inf.OID],
			filepath.Join(destbase, fn))
		oids = append(oids, inf.OID)
	}

	err = client.Blobs(*totalConcurrency, *nodeConcurrency,
		func(oid string, r io.Reader) error {
			return saveDownload(dests[oid], oid, r)
		}, oids...)

	cbfstool.MaybeFatal(err, "Error getting blobs: %v", err)

	b := atomic.AddInt64(&totalBytes, 0)
	d := time.Since(start)
	cbfstool.Verbose(*dlverbose, "Moved %s in %v (%s/s)", humanize.Bytes(uint64(b)),
		d, humanize.Bytes(uint64(float64(b)/d.Seconds())))
}
예제 #2
0
파일: find.go 프로젝트: 40a/cbfs
func findCommand(u string, args []string) {
	if *findDashName != "" && *findDashIName != "" {
		log.Fatalf("Can't specify both -name and -iname")
	}
	src := findFlags.Arg(0)
	for src[len(src)-1] == '/' {
		src = src[:len(src)-1]
	}

	tmpl := cbfstool.GetTemplate(*findTemplate, *findTemplateFile,
		defaultFindTemplate)

	httputil.InitHTTPTracker(false)

	client, err := cbfsclient.New(u)
	cbfstool.MaybeFatal(err, "Can't build a client: %v", err)

	things, err := client.ListDepth(src, *findDashDepth)
	cbfstool.MaybeFatal(err, "Can't list things: %v", err)

	metaMatcher := findGetRefTimeMatch(time.Now())
	matcher := newDirAndFileMatcher()
	for fn, inf := range things.Files {
		if !metaMatcher(inf.Modified) {
			continue
		}
		if len(fn) > len(src)+1 {
			fn = fn[len(src)+1:]
		}
		for _, match := range matcher.matches(fn) {
			if err := tmpl.Execute(os.Stdout, struct {
				Name  string
				IsDir bool
				Meta  cbfsclient.FileMeta
			}{match.path, match.isDir, inf}); err != nil {
				log.Fatalf("Error executing template: %v", err)
			}
		}
	}
}