Esempio n. 1
0
func openOwner(dir string) (o wOwner, err error) {
	o.dir = dir
	o.buckets = make(map[string]wBucket, 4)

	var k, nm string

	err = weedutils.MapDirItems(dir,
		func(fi os.FileInfo) bool {
			return fi.Mode().IsRegular() && strings.HasSuffix(fi.Name(), ".kv")
		},
		func(fi os.FileInfo) error {
			nm = fi.Name()
			k = nm[:len(nm)-3]
			o.buckets[k], err = openBucket(filepath.Join(dir, nm))
			return err
		})
	return
}
Esempio n. 2
0
// NewWeedS3 stores everything in the given master Weed-FS node
// buckets are stored
func NewWeedS3(masterURL, dbdir string) (s3intf.Storage, error) {
	m := master{wm: weed.NewWeedClient(masterURL), baseDir: dbdir,
		owners: make(map[string]wOwner, 4)}
	dh, err := os.Open(dbdir)
	if err != nil {
		if _, ok := err.(*os.PathError); !ok {
			return nil, err
		}
		os.MkdirAll(dbdir, 0750)
	}
	defer dh.Close()
	var nm string
	err = weedutils.MapDirItems(dbdir,
		func(fi os.FileInfo) bool {
			return fi.Mode().IsDir()
		},
		func(fi os.FileInfo) error {
			nm = fi.Name()
			m.owners[nm], err = openOwner(filepath.Join(dbdir, nm))
			return err
		})
	return m, err
}