Example #1
0
func loadPicIndex() {
	nBlobs := 10
	for skip := 0; true; skip += nBlobs {
		blobs, err := c.BlobsBackward(time.Now(), nBlobs, skip)
		if err != nil {
			break
		}
		for _, b := range blobs {
			if b.Type() == photos.IndexType {
				err := blob.Unmarshal(b, picIndex)
				util.Check(err)
				return
			}
		}

		if len(blobs) < nBlobs {
			break
		}
	}

	// no pre-existing photo index found
	picIndex = photos.NewIndex()
	obj := blob.NewObject()
	picIndex.RcasObjectRef = obj.Ref()
	err := c.PutBlob(obj)
	if err != nil {
		panic("pics: could not create photo index")
	}
}
Example #2
0
func picForObj(ref string) *photos.Photo {
	b, err := c.ObjectTip(ref)
	util.Check(err)
	p := &photos.Photo{}
	err = blob.Unmarshal(b, p)
	util.Check(err)
	return p
}
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
// Unpack mounts files associated with each given ref into the directory
// specified by Root and the associated Meta's mount meta-data.
func (m *Mount) Unpack(refs ...string) error {
	err := m.Client.Dial()
	if err != nil {
		return err
	}

	m.Refs = map[string]string{}
	for _, ref := range refs {
		b, err := m.Client.GetBlob(ref)
		if err != nil {
			return err
		}

		fm := &blob.Meta{}
		err = blob.Unmarshal(b, fm)

		fm, data, err := m.Client.ReconstituteFile(b.Ref())
		if err != nil {
			return err
		}

		pth := m.PathFor(fm)
		if pth == "" {
			continue
		}

		full := filepath.Join(m.Root, pth)
		os.MkdirAll(filepath.Dir(full), 0744)
		f, err := os.Create(full)
		if err != nil {
			return err
		}
		f.Write(data)
		f.Close()
		pth = keyClean(pth)
		m.Refs[pth] = ref
	}
	return nil
}
Example #5
0
// getTip returns the Meta blob for the most recent version of the object
// for which the file specified by path is a part.
func (m *Mount) getTip(path string) (*blob.Meta, error) {
	path = keyClean(path)

	var fm = &blob.Meta{}
	if ref, ok := m.Refs[path]; ok {
		b, err := m.Client.GetBlob(ref)
		if err != nil {
			return nil, err
		}

		b, err = m.Client.ObjectTip(b.ObjectRef())
		if err != nil {
			return nil, err
		}
		err = blob.Unmarshal(b, fm)
		if err != nil {
			return nil, err
		}
		return fm, nil
	}
	return nil, UntrackedErr
}
Example #6
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
}
Example #7
0
// Unauthorized checks for and handles cases where authentication can occur via
// share blobs.
func (h *getHandler) Unauthorized(w http.ResponseWriter, req *http.Request) {
	defer func() {
		if r := recover(); r != nil {
			w.Header().Set(ActionStatus, ActionFailed)
			fmt.Println("blob post failed: ", r)
		}
	}()

	shareRef := req.FormValue("via")
	if shareRef == "" {
		auth.SendUnauthorized(w)
		return
	}

	b, err := h.bs.Db.Get(shareRef)
	if err != nil {
		auth.SendUnauthorized(w)
		return
	}

	share := &blob.Share{}
	err = blob.Unmarshal(b, share)
	util.Check(err)

	ref := path.Base(req.URL.Path)
	b, err = h.bs.Db.Get(ref)
	util.Check(err)

	if !share.AuthorizedGet(b) {
		auth.SendUnauthorized(w)
		return
	}

	w.Header().Set(ActionStatus, ActionSuccess)
	w.Write(b.Content())
	fmt.Println("successful retrieval")
}