Beispiel #1
0
func indexTag(inTag objects.Tag) {
	indexBlob(inTag.Bytes())
	hashHex := inTag.Hash().Hex()
	blobIndex[hashHex] = blobIndex[hashHex].insertType("Tag")
	blobIndex[inTag.Hkid.Hex()] =
		blobIndex[inTag.Hkid.Hex()].insertType("Domain")
	blobIndex[hashHex] =
		blobIndex[hashHex].insertCollection(inTag.Hkid.Hex())
	indexNameSegment(
		inTag.TypeString,
		inTag.HashBytes.Hex(),
		inTag.Hash().Hex(),
		inTag.NameSegment,
	)

	if tagIndex == nil {
		tagIndex = make(map[string]tagIndexEntry)
	}
	if _, present := tagIndex[inTag.Hkid.Hex()]; !present {
		tagIndex[inTag.Hkid.Hex()] = tagIndexEntry{}
	}
	tagIndex[inTag.Hkid.Hex()] = tagIndex[inTag.Hkid.Hex()].insertVersion(
		inTag.Version,
		inTag.NameSegment,
		inTag.Hash(),
	)
	insertDescendantS(inTag.Parents, inTag.Hash(), inTag.Version)
}
Beispiel #2
0
func (lfs localfileservice) PostTag(t objects.Tag) (err error) {
	lfs.PostBlob(objects.Blob(t.Bytes()))
	filepath := fmt.Sprintf("bin/tags/%s/%s/%d", t.Hkid.Hex(),
		t.NameSegment, t.Version)
	//log.Printf("[localfileservice] PostTag %s", filepath)
	dirpath := fmt.Sprintf("bin/tags/%s/%s", t.Hkid.Hex(),
		t.NameSegment)
	err = os.MkdirAll(dirpath, 0764)
	err = ioutil.WriteFile(filepath, t.Bytes(), 0664)
	return
}
Beispiel #3
0
func (k kademliaservice) PostTag(t objects.Tag) (err error) {
	values := url.Values{}
	values.Add("type", "tag")
	values.Add("hkid", t.Hkid.Hex())
	values.Add("namesegment", t.NameSegment)
	_, err = k.postobject(values, t.Bytes())
	if err != nil {
		log.Println(err)
		return err
	}
	//log.Printf("Responce: %s", data)
	return err
}
Beispiel #4
0
func (d dir) Publish(h objects.HCID, name string, typeString string) (err error) {
	switch d.contentType {

	default:
		log.Printf("unknown type: %s", d.contentType)
		return fmt.Errorf("unknown type: %s", d.contentType)
	case "commit":
		c, CommitErr := services.GetCommit(d.leaf.(objects.HKID))
		if CommitErr != nil {
			return CommitErr
		}
		l, listErr := services.GetList(c.ListHash)
		if listErr != nil {
			return listErr
		}
		newList := l.Add(name, h, typeString)

		newCommit := c.Update(newList.Hash())
		//=========================================================================
		//if verbosity == 1 {
		log.Printf(
			"Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------",
			newList.Hash(),
			newList,
		)
		//}
		//=========================================================================
		el := services.PostList(newList)
		if el != nil {
			return listErr
		}
		//=========================================================================
		//if verbosity == 1 {
		log.Printf(
			"Posting commit %s\n-----BEGIN COMMIT-----\n%s\n-------END COMMIT-----",
			newCommit.Hash(),
			newCommit,
		)
		//}
		//=========================================================================
		ec := services.PostCommit(newCommit)
		if ec != nil {
			return listErr
		}
		return nil
	case "tag":
		t, tagErr := services.GetTag(d.leaf.(objects.HKID), name)
		var newTag objects.Tag
		if tagErr == nil {
			newTag = t.Update(h, typeString)
		} else {
			log.Printf("Tag %s\\%s Not Found", d.leaf, name)
			newTag = objects.NewTag(h, typeString, name, nil, d.leaf.(objects.HKID))
		}
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting tag %s\n-----BEGIN TAG--------\n%s\n-------END TAG--------",
				newTag.Hash(),
				newTag,
			)
		}
		//=========================================================================
		et := services.PostTag(newTag)
		if et != nil {
			return tagErr
		}
		return nil
	case "list":
		l, listErr := services.GetList(d.leaf.(objects.HCID))
		if listErr != nil {
			return listErr
		}
		newList := l.Add(name, h, typeString)
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------",
				newList.Hash(),
				newList,
			)
		}
		//=========================================================================
		el := services.PostList(newList)
		if el != nil {
			return listErr
		}
		d.parent.Publish(newList.Hash(), d.name, "list")
		return nil
	}
}
Beispiel #5
0
func (d dir) Rename(
	r *fuse.RenameRequest,
	newDir fs.Node,
	intr fs.Intr,
) fuse.Error {
	log.Printf("request: %+v\nobject: %+v", r, d)
	select {
	case <-intr:
		return fuse.EINTR
	default:
	}
	//find content_type
	if r.OldName != r.NewName {
		d.name = r.NewName
	}
	d.name = r.OldName

	switch d.contentType {

	case "list":
		l, listErr := services.GetList(d.leaf.(objects.HCID))
		if listErr != nil {
			return listErr
		}
		newList := l.Add(r.NewName, l[r.OldName].Hash, l[r.OldName].TypeString)
		newList = l.Remove(r.OldName)
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------",
				newList.Hash(),
				newList,
			)
		}
		//=========================================================================
		el := services.PostList(newList)
		if el != nil {
			return listErr
		}
		d.Publish(d.leaf.(objects.HCID), d.name, d.contentType)

	case "commit":
		c, CommitErr := services.GetCommit(d.leaf.(objects.HKID))
		if CommitErr != nil {
			return CommitErr
		}
		l, ListErr := services.GetList(c.ListHash)
		if ListErr != nil {
			return ListErr
		}
		newList := l.Add(r.NewName, l[r.OldName].Hash, l[r.OldName].TypeString)
		newList = l.Remove(r.OldName)

		newCommit := c.Update(newList.Hash())
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------",
				newList.Hash(),
				newList,
			)
		}
		//=========================================================================
		el := services.PostList(newList)
		if el != nil {
			return ListErr
		}
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting commit %s\n-----BEGIN COMMIT-----\n%s\n-------END COMMIT-----",
				newCommit.Hash(),
				newCommit,
			)
		}
		//=========================================================================
		ec := services.PostCommit(newCommit)
		if ec != nil {
			return ListErr
		}

	case "tag":

		oldTag, tagErr := services.GetTag(d.leaf.(objects.HKID), r.OldName)
		var newTag objects.Tag
		if tagErr == nil {
			newTag = objects.NewTag(
				oldTag.HashBytes,
				oldTag.TypeString,
				r.NewName,
				[]objects.HCID{oldTag.Hash()},
				d.leaf.(objects.HKID),
			)
		} else {
			log.Printf("Tag %s\\%s Not Found", d.leaf, d.name)
			return fuse.ENOENT
		}
		//=========================================================================
		if verbosity == 1 {
			log.Printf(
				"Posting tag %s\n-----BEGIN TAG--------\n%s\n-------END TAG--------",
				newTag.Hash(),
				newTag,
			)
		}
		//=========================================================================
		et := services.PostTag(newTag)
		if et != nil {
			return tagErr
		}
	} //end switch

	return nil
}
Beispiel #6
0
func get(objecthash objects.HID, path string, typeString string) (b objects.Blob, err error) {
	//typeString := "commit"
	err = nil
	nameSegments := []string{"", path}
	for {
		if len(nameSegments) > 1 {
			nameSegments = strings.SplitN(nameSegments[1], "/", 2)
		} else {
			nameSegments = []string{""}
		}
		//log.Printf("\n\tPath: %s\n\tType: %v\n\tobjecthash: %v\n",
		//	nameSegments, typeString, objecthash)
		switch typeString {
		case "blob":
			b, err = GetBlob(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			return b, err
		case "list":
			var l objects.List
			l, err = GetList(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			typeString, objecthash = l.HashForNamesegment(nameSegments[0])
			if objecthash == nil && nameSegments[0] != "" {
				err = fmt.Errorf("Blob not found")
			}
			b = l.Bytes()
		case "tag":
			var t objects.Tag
			//if nameSegments[0] == "" {
			//	log.Printf("\n\tNo Path\n")
			//}
			t, err = GetTag(objecthash.(objects.HKID), nameSegments[0])
			if err != nil {
				//log.Printf("\n\t%v\n", err)
				return nil, err
			}
			if !t.Verify() {
				return nil, fmt.Errorf("Tag Verify Failed")
			}
			typeString = t.TypeString
			objecthash = t.HashBytes
			b = t.Bytes()
		case "commit":
			var c objects.Commit
			c, err = GetCommit(objecthash.Bytes())
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			if !c.Verify() {
				return nil, fmt.Errorf("Commit Verify Failed")
			}
			var l objects.List
			l, err = GetList(c.ListHash)
			if err != nil {
				log.Printf("\n\t%v\n", err)
			}
			typeString, objecthash = l.HashForNamesegment(nameSegments[0])
			if objecthash == nil && nameSegments[0] != "" {
				err = fmt.Errorf("Blob not found")
			}
			//if err != nil {
			//	log.Printf("%v\n", err)
			//}
			b = l.Bytes()
		default:
			log.Printf("\n\t%v\n", err)
			panic(err)
		}
		//if len(nameSegments) == 1 && typeString != "blob" {
		if objecthash == nil {
			return b, err
		}
	}
}