Esempio n. 1
0
// If modTime is zero, it's not used.
func (id *IndexDeps) UploadDir(dirName string, children []blob.Ref, modTime time.Time) blob.Ref {
	// static-set entries blob
	ss := new(schema.StaticSet)
	for _, child := range children {
		ss.Add(child)
	}
	ssjson := ss.Blob().JSON()
	ssb := &test.Blob{Contents: ssjson}
	id.BlobSource.AddBlob(ssb)
	_, err := id.Index.ReceiveBlob(ssb.BlobRef(), ssb.Reader())
	if err != nil {
		id.Fatalf("UploadDir.ReceiveBlob: %v", err)
	}

	// directory blob
	bb := schema.NewDirMap(dirName)
	bb.PopulateDirectoryMap(ssb.BlobRef())
	if !modTime.IsZero() {
		bb.SetModTime(modTime)
	}
	dirjson, err := bb.JSON()
	if err != nil {
		id.Fatalf("UploadDir.JSON: %v", err)
	}
	dirb := &test.Blob{Contents: dirjson}
	id.BlobSource.AddBlob(dirb)
	_, err = id.Index.ReceiveBlob(dirb.BlobRef(), dirb.Reader())
	if err != nil {
		id.Fatalf("UploadDir.ReceiveBlob: %v", err)
	}
	return dirb.BlobRef()
}
Esempio n. 2
0
func (c *makeStaticCmd) RunCommand(args []string) error {
	if len(args) != 1 {
		return cmdmain.UsageError("requires a permanode")
	}
	pn, ok := blob.Parse(args[0])
	if !ok {
		return cmdmain.UsageError("invalid permanode argument")
	}

	cl := newClient(c.server)
	res, err := cl.Describe(&search.DescribeRequest{
		BlobRefs: []blob.Ref{pn},
		Rules: []*search.DescribeRule{
			{
				IfResultRoot: true,
				Attrs:        []string{"camliMember"},
				Rules: []*search.DescribeRule{
					{Attrs: []string{"camliContent"}},
				},
			},
		},
	})
	if err != nil {
		return err
	}

	camliType := func(ref string) string {
		m := res.Meta[ref]
		if m == nil {
			return ""
		}
		return m.CamliType
	}

	var ss schema.StaticSet
	pnDes, ok := res.Meta[pn.String()]
	if !ok {
		return fmt.Errorf("permanode %v not described", pn)
	}
	if pnDes.Permanode == nil {
		return fmt.Errorf("blob %v is not a permanode", pn)
	}
	members := pnDes.Permanode.Attr["camliMember"]
	if len(members) == 0 {
		return fmt.Errorf("permanode %v has no camliMember attributes", pn)
	}
	for _, fileRefStr := range members {
		if camliType(fileRefStr) != "permanode" {
			continue
		}
		contentRef := res.Meta[fileRefStr].Permanode.Attr.Get("camliContent")
		if contentRef == "" {
			continue
		}
		if camliType(contentRef) == "file" {
			ss.Add(blob.MustParse(contentRef))
		}
	}

	b := ss.Blob()
	_, err = cl.UploadBlob(b)
	if err != nil {
		return err
	}
	title := pnDes.Title()
	title = strings.Replace(title, string(os.PathSeparator), "", -1)
	if title == "" {
		title = pn.String()
	}
	dir := schema.NewDirMap(title).PopulateDirectoryMap(b.BlobRef())
	dirBlob := dir.Blob()
	_, err = cl.UploadBlob(dirBlob)
	if err == nil {
		fmt.Println(dirBlob.BlobRef().String())
	}
	return err
}