コード例 #1
0
ファイル: camput.go プロジェクト: ipeet/camlistore
func makeUploader() *Uploader {
	cc := client.NewOrFail()
	if !*flagVerbose {
		cc.SetLogger(nil)
	}

	transport := new(tinkerTransport)
	transport.transport = &http.Transport{DisableKeepAlives: false}
	cc.SetHttpClient(&http.Client{Transport: transport})

	pwd, err := os.Getwd()
	if err != nil {
		log.Fatalf("os.Getwd: %v", err)
	}

	up := &Uploader{
		Client:    cc,
		transport: transport,
		pwd:       pwd,
		filecapc:  make(chan bool, 10 /* TODO: config option on max files at a time */),
		entityFetcher: &jsonsign.CachingEntityFetcher{
			Fetcher: &jsonsign.FileEntityFetcher{File: cc.SecretRingFile()},
		},
	}
	return up
}
コード例 #2
0
ファイル: main.go プロジェクト: ipeet/camlistore
// TODO(rh): tame copy/paste code from cammount
func main() {
	flag.Parse()
	cacheDir, err := ioutil.TempDir("", "camlicache")
	if err != nil {
		log.Fatalf("Error creating temp cache directory: %v", err)
	}
	defer os.RemoveAll(cacheDir)
	diskcache, err := localdisk.New(cacheDir)
	if err != nil {
		log.Fatalf("Error setting up local disk cache: %v", err)
	}
	if flag.NArg() != 1 {
		log.Fatal("usage: camwebdav <blobref>")
	}
	br := blobref.Parse(flag.Arg(0))
	if br == nil {
		log.Fatalf("%s was not a valid blobref.", flag.Arg(0))
	}
	client := client.NewOrFail()
	fetcher := cacher.NewCachingFetcher(diskcache, client)

	f = fs.NewCamliFileSystem(fetcher, br)
	http.HandleFunc("/", webdav)
	err = http.ListenAndServe(*davaddr, nil)
	if err != nil {
		log.Fatalf("Error starting WebDAV server: %v", err)
	}
}
コード例 #3
0
ファイル: camput.go プロジェクト: marsch/camlistore
func main() {
	flag.Parse()

	if sumSet(flagFile, flagBlob, flagPermanode, flagInit, flagShare) != 1 {
		// TODO: say which ones are conflicting
		usage("Conflicting mode options.")
	}

	client := client.NewOrFail()
	if !*flagVerbose {
		client.SetLogger(nil)
	}
	uploader := &Uploader{client}

	switch {
	case *flagInit:
		doInit()
		return
	case *flagPermanode:
		if flag.NArg() > 0 {
			log.Exitf("--permanode doesn't take any additional arguments")
		}
		pr, err := uploader.UploadNewPermanode()
		handleResult("permanode", pr, err)
	case *flagFile || *flagBlob:
		for n := 0; n < flag.NArg(); n++ {
			if *flagBlob {
				pr, err := uploader.UploadFileBlob(flag.Arg(n))
				handleResult("blob", pr, err)
			} else {
				pr, err := uploader.UploadFile(flag.Arg(n))
				handleResult("file", pr, err)
			}
		}
	case *flagShare:
		if flag.NArg() != 1 {
			log.Exitf("--share only supports one blobref")
		}
		br := blobref.Parse(flag.Arg(0))
		if br == nil {
			log.Exitf("BlobRef is invalid: %q", flag.Arg(0))
		}
		pr, err := uploader.UploadShare(br, *flagTransitive)
		handleResult("share", pr, err)
	}

	if *flagVerbose {
		stats := uploader.Stats()
		log.Printf("Client stats: %s", stats.String())
	}
	if wereErrors {
		os.Exit(2)
	}
}
コード例 #4
0
ファイル: camget.go プロジェクト: ipeet/camlistore
func main() {
	flag.Parse()

	client := client.NewOrFail()
	if *flagCheck {
		// Simply do HEAD requests checking if the blobs exists.
		return
	}

	var w io.Writer = os.Stdout

	for n := 0; n < flag.NArg(); n++ {
		arg := flag.Arg(n)
		br := blobref.Parse(arg)
		if br == nil {
			log.Fatalf("Failed to parse argument \"%s\" as a blobref.", arg)
		}
		if *flagVerbose {
			log.Printf("Need to fetch %s", br.String())
		}
		var (
			r   io.ReadCloser
			err os.Error
		)

		if len(*flagVia) > 0 {
			vs := strings.Split(*flagVia, ",")
			abr := make([]*blobref.BlobRef, len(vs))
			for i, sbr := range vs {
				abr[i] = blobref.Parse(sbr)
				if abr[i] == nil {
					log.Fatalf("Invalid -via blobref: %q", sbr)
				}
				if *flagVerbose {
					log.Printf("via: %s", sbr)
				}
			}
			r, _, err = client.FetchVia(br, abr)
		} else {
			r, _, err = client.FetchStreaming(br)
		}
		if err != nil {
			log.Fatalf("Failed to fetch %q: %s", br, err)
		}
		defer r.Close()
		_, err = io.Copy(w, r)
		if err != nil {
			log.Fatalf("Failed transferring %q: %s", br, err)
		}
	}

}
コード例 #5
0
ファイル: main.go プロジェクト: ipeet/camlistore
func main() {
	// Scans the arg list and sets up flags
	debug := flag.Bool("debug", false, "print debugging messages.")
	threaded := flag.Bool("threaded", true, "switch off threading; print debugging messages.")
	flag.Parse()

	errorf := func(msg string, args ...interface{}) {
		fmt.Fprintf(os.Stderr, msg, args...)
		os.Exit(2)
	}

	if flag.NArg() < 2 {
		errorf("usage: cammount <blobref> <mountpoint>\n")
	}

	root := blobref.Parse(flag.Arg(0))
	if root == nil {
		errorf("Error parsing root blobref: %q\n", root)
	}
	client := client.NewOrFail() // automatic from flags

	cacheDir, err := ioutil.TempDir("", "camlicache")
	if err != nil {
		errorf("Error creating temp cache directory: %v\n", err)
	}
	defer os.RemoveAll(cacheDir)
	diskcache, err := localdisk.New(cacheDir)
	if err != nil {
		errorf("Error setting up local disk cache: %v", err)
	}
	fetcher := cacher.NewCachingFetcher(diskcache, client)

	fs := fs.NewCamliFileSystem(fetcher, root)
	timing := fuse.NewTimingPathFilesystem(fs)

	conn := fuse.NewPathFileSystemConnector(timing)
	rawTiming := fuse.NewTimingRawFilesystem(conn)

	state := fuse.NewMountState(rawTiming)
	state.Debug = *debug

	mountPoint := flag.Arg(1)
	err = state.Mount(mountPoint)
	if err != nil {
		fmt.Printf("MountFuse fail: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", root.String(), mountPoint, *threaded, *debug)
	state.Loop(*threaded)
	fmt.Println("Finished", state.Stats())

	counts := state.OperationCounts()
	fmt.Println("Counts: ", counts)

	latency := state.Latencies()
	fmt.Println("MountState latency (ms):")
	PrintMap(latency)

	latency = timing.Latencies()
	fmt.Println("Path ops (ms):", latency)

	latency = rawTiming.Latencies()
	fmt.Println("Raw FS (ms):", latency)
}
コード例 #6
0
ファイル: camput.go プロジェクト: rvijax/camlistore
func main() {
	jsonsign.AddFlags()
	flag.Parse()

	if *flagSplits {
		showSplits()
		return
	}

	nOpts := sumSet(flagFile, flagBlob, flagPermanode, flagInit, flagShare, flagRemove,
		flagSetAttr, flagAddAttr)
	if !(nOpts == 1 ||
		(nOpts == 2 && *flagFile && *flagPermanode)) {
		usage("Conflicting mode options.")
	}

	cc := client.NewOrFail()
	if !*flagVerbose {
		cc.SetLogger(nil)
	}
	up := &Uploader{
		Client: cc,
		entityFetcher: &jsonsign.CachingEntityFetcher{
			Fetcher: &jsonsign.FileEntityFetcher{File: cc.SecretRingFile()},
		},
	}
	switch {
	case *flagInit:
		doInit()
		return
	case *flagFile || *flagBlob:
		var (
			permaNode *client.PutResult
			lastPut   *client.PutResult
			err       os.Error
		)
		if n := flag.NArg(); *flagPermanode {
			if n != 1 {
				log.Fatalf("Options --permanode and --file can only be used together when there's exactly one argument")
			}
			permaNode, err = up.UploadNewPermanode()
			if err != nil {
				log.Fatalf("Error uploading permanode: %v", err)
			}
		}
		for n := 0; n < flag.NArg(); n++ {
			if *flagBlob {
				lastPut, err = up.UploadFileBlob(flag.Arg(n))
				handleResult("blob", lastPut, err)
			} else {
				lastPut, err = up.UploadFile(flag.Arg(n))
				handleResult("file", lastPut, err)
			}
		}
		if permaNode != nil {
			put, err := up.UploadAndSignMap(schema.NewSetAttributeClaim(permaNode.BlobRef, "camliContent", lastPut.BlobRef.String()))
			handleResult("claim-permanode-content", put, err)
			if *flagName != "" {
				put, err := up.UploadAndSignMap(schema.NewSetAttributeClaim(permaNode.BlobRef, "name", *flagName))
				handleResult("claim-permanode-name", put, err)
			}
			handleResult("permanode", permaNode, nil)
		}
	case *flagPermanode:
		if flag.NArg() > 0 {
			log.Fatalf("--permanode doesn't take any additional arguments")
		}
		pr, err := up.UploadNewPermanode()
		handleResult("permanode", pr, err)
		if *flagName != "" {
			put, err := up.UploadAndSignMap(schema.NewSetAttributeClaim(pr.BlobRef, "name", *flagName))
			handleResult("permanode-name", put, err)
		}
	case *flagShare:
		if flag.NArg() != 1 {
			log.Fatalf("--share only supports one blobref")
		}
		br := blobref.Parse(flag.Arg(0))
		if br == nil {
			log.Fatalf("BlobRef is invalid: %q", flag.Arg(0))
		}
		pr, err := up.UploadShare(br, *flagTransitive)
		handleResult("share", pr, err)
	case *flagRemove:
		if flag.NArg() == 0 {
			log.Fatalf("--remove takes one or more blobrefs")
		}
		err := up.RemoveBlobs(blobref.ParseMulti(flag.Args()))
		if err != nil {
			log.Printf("Error removing blobs %s: %s", strings.Join(flag.Args(), ","), err)
			wereErrors = true
		}
	case *flagAddAttr || *flagSetAttr:
		if flag.NArg() != 3 {
			log.Fatalf("--set-attr and --add-attr take 3 args: <permanode> <attr> <value>")
		}
		pn := blobref.Parse(flag.Arg(0))
		if pn == nil {
			log.Fatalf("Error parsing blobref %q", flag.Arg(0))
		}
		m := schema.NewSetAttributeClaim(pn, flag.Arg(1), flag.Arg(2))
		if *flagAddAttr {
			m = schema.NewAddAttributeClaim(pn, flag.Arg(1), flag.Arg(2))
		}
		put, err := up.UploadAndSignMap(m)
		handleResult(m["claimType"].(string), put, err)
	}

	if *flagVerbose {
		stats := up.Stats()
		log.Printf("Client stats: %s", stats.String())
	}
	if wereErrors {
		os.Exit(2)
	}
}