Example #1
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 #2
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 #3
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 #4
0
func filtFn(b *blob.Blob) bool {
	f := blob.NewMeta()
	err := blob.Unmarshal(b, f)
	if err != nil {
		return false
	}

	mm := &mount.Meta{}
	err = f.GetNotes(mount.Key, mm)
	if err != nil {
		mm = &mount.Meta{}
	}

	if !strings.HasPrefix(mm.Path, strings.Trim(*prefix, "./\\")) {
		return false
	} else if !*showOld && !isTip(b) {
		return false
	} else if !*showHidden && mm.Hidden {
		return false
	}
	return true
}