Example #1
0
func testFile() {
	db, err := blobdb.New(dbpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	meta := blob.NewMeta()
	blobs, err := meta.LoadFromPath(testfilepath)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.Put(blobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	m, _ := blob.Marshal(meta)
	err = db.Put(m)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, b := range blobs {
		fmt.Println(b)
	}
}
Example #2
0
func sendFileBlobs(c *blobserv.Client, part *multipart.Part) (respMeta map[string]interface{}) {
	meta := blob.NewMeta()
	defer func() {
		respMeta = map[string]interface{}{}
		respMeta["name"] = meta.Name
		respMeta["size"] = meta.Size

		if r := recover(); r != nil {
			respMeta["error"] = r.(error).Error()
		}
	}()

	obj := blob.NewObject()
	meta.RcasObjectRef = obj.Ref()
	meta.Name = part.FileName()

	data, err := ioutil.ReadAll(part)
	util.Check(err)

	meta.Size = int64(len(data))

	blobs := blob.SplitRaw(data, blob.DefaultChunkSize)
	meta.ContentRefs = blob.RefsFor(blobs)

	m, err := blob.Marshal(meta)
	util.Check(err)

	blobs = append(blobs, m, obj)
	for _, b := range blobs {
		err = c.PutBlob(b)
		util.Check(err)
	}

	return respMeta
}
Example #3
0
func testTimeIndex() {
	ti := timeindex.New()

	m1 := map[string]string{}
	m2 := map[string]string{}
	m3 := map[string]string{}
	m4 := map[string]string{}
	m5 := map[string]string{}

	b1, _ := blob.Marshal(m1)
	time.Sleep(time.Second * 1)
	b2, _ := blob.Marshal(m2)
	time.Sleep(time.Second * 1)
	b3, _ := blob.Marshal(m3)
	time.Sleep(time.Second * 1)
	b4, _ := blob.Marshal(m4)
	time.Sleep(time.Second * 1)
	b5, _ := blob.Marshal(m5)

	ti.Notify(b1, b2, b3, b4, b5)

	var m map[string]string
	blob.Unmarshal(b4, &m)
	t, _ := time.Parse(blob.TimeFormat, m[blob.Timestamp])

	i := ti.IndexNear(t.Add(time.Millisecond * -1))
	ref := ti.RefAt(i)

	fmt.Println("retrieved ref:", ref)

	fmt.Println("all refs:")
	fmt.Println(b1.Ref())
	fmt.Println(b2.Ref())
	fmt.Println(b3.Ref())
	fmt.Println(b4.Ref())
	fmt.Println(b5.Ref())

	if ref == b3.Ref() {
		fmt.Println("success!")
	} else {
		fmt.Println("failured")
	}
}
Example #4
0
// SetMeta sets the mount Notes associated with the given file.
func (m *Mount) SetMeta(pth string, mm *Meta) (err error) {
	defer func() { recover() }()

	fm, err := m.getTip(pth)
	util.Check(err)
	err = fm.SetNotes(Key, mm)
	util.Check(err)

	b, err := blob.Marshal(fm)
	util.Check(err)
	err = m.Client.PutBlob(b)
	util.Check(err)

	return nil
}
Example #5
0
// Snap creates and sends an object-associated, updated snapshot of a file's
// bytes to the blobserver.
//
// All meta-data associated with the file is left unchanged.
func (m *Mount) Snap(path string) error {
	path = keyClean(path)

	var chunks []*blob.Blob
	newfm, err := m.getTip(path)
	if err == UntrackedErr {
		newfm = blob.NewMeta()
		obj := blob.NewObject()
		newfm.RcasObjectRef = obj.Ref()
		chunks, err = newfm.LoadFromPath(path)
		if err != nil {
			return err
		}

		mpath := filepath.Dir(filepath.Join(m.Prefix, m.keyPath(path)))
		newfm.SetNotes(Key, &Meta{Path: mpath})
		chunks = append(chunks, obj)
	} else if err != nil {
		return err
	}

	chunks, err = newfm.LoadFromPath(path)
	if err != nil {
		return err
	}

	b, err := blob.Marshal(newfm)
	if err != nil {
		return err
	}
	chunks = append(chunks, b)

	m.Refs[path] = b.Ref()

	for _, b := range chunks {
		err := m.Client.PutBlob(b)
		if err != nil {
			return err
		}
	}
	return nil
}
Example #6
0
func putnote(c *blobserv.Client, w http.ResponseWriter, req *http.Request) {
	defer util.DeferWrite(w)

	body, err := ioutil.ReadAll(req.Body)
	util.Check(err)

	var note map[string]interface{}
	err = json.Unmarshal(body, &note)
	util.Check(err)

	note[blob.Type] = myType

	b, err := blob.Marshal(note)
	util.Check(err)

	err = c.PutBlob(b)
	util.Check(err)

	w.Write(b.Content())
}
Example #7
0
func testDir() {
	db, _ := blobdb.New(dbpath)

	metas, blobs, err := blob.DirBlobsAndMeta(testdirpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	metablobs := make([]*blob.Blob, 0)
	for _, meta := range metas {
		obj := blob.NewObject()
		meta.RcasObjectRef = obj.Ref()
		m, _ := blob.Marshal(meta)
		metablobs = append(metablobs, m, obj)
	}

	err = db.Put(metablobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.Put(blobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, b := range metablobs {
		fmt.Println(b)
	}
	for _, b := range blobs {
		fmt.Println(b)
	}
}