示例#1
0
文件: testutil.go 项目: nullren/kebab
func Setup() {
	flag.Parse()

	var err error
	wd, err := os.Getwd()
	if err != nil {
		log.Fatalf("os.Getwd: %s", err)
	}
	TempDir, err = ioutil.TempDir(wd, "kebab_testing_")
	if err != nil {
		log.Fatalf("ioutil.TempDir failed: %s", err)
	}

	stdlog := log.New(os.Stderr, "RecoverableBucketLog: ", 0)
	PromptLog = &bucket.PromptLogger{Logger: stdlog}

	if *s3conf != "" {
		s3b, err := bucket.NewS3BucketFromFile(*s3conf)
		if err != nil {
			log.Fatalf("bucket.NewS3BucketFromFile: %s", err)
		}

		tmp := fmt.Sprintf("kebab_testing_%x", RandomBytes(4))
		TempS3, err = s3b.Descend(tmp)
		if err != nil {
			log.Fatalf("Descend(%q): %s", tmp, err)
		}
		SkipS3 = false
	}
}
示例#2
0
文件: bucket.go 项目: nullren/kebab
func openBucket(bucketPath string) (bucket.Bucket, error) {
	file, err := os.Open(bucketPath)
	if err != nil {
		return nil, err
	}
	fi, err := file.Stat()
	if err != nil {
		return nil, err
	}

	if fi.IsDir() {
		return bucket.NewFileBucket(bucketPath)
	} else {
		b, err := bucket.NewS3BucketFromFile(bucketPath)
		if err != nil {
			return nil, fmt.Errorf("bucket.NewS3BucketFromFile: %s", err)
		}
		return b, nil
	}
}