Example #1
0
func BenchmarkLowLevelRemoveBlob(b *testing.B) {

	//Generate HKID from Private Key String
	commitHkid := objects.HkidFromDString("25237284271696152257500017172738061121437774519248"+
		"4973944393756241918592441392745192478415977843322020140748800825891925253"+
		"1173359792875255431921541368062567", 10)

	for i := 0; i < b.N; i++ {

		//Create Blob and add it to Commit List
		testBlob := objects.Blob([]byte("BlobToBeDeleted"))
		_ = services.PostBlob(testBlob)
		testList := objects.NewList(testBlob.Hash(), "blob", "blobToBeDeleted")
		services.PostList(testList)
		testCommit := objects.NewCommit(testList.Hash(), commitHkid)
		services.PostCommit(testCommit)

		//Check to make sure Blob was added to Commit List
		commitFromHkid, err := services.GetCommit(commitHkid)
		_, err = services.GetList(commitFromHkid.ListHash)
		listEntry, found := testList["blobToBeDeleted"]
		if !found {
			b.Fatalf("Error: Blob could not be found in list")
		}
		_, err = services.GetBlob(listEntry.Hash.(objects.HCID))
		if err != nil {
			b.Fatalf("Error: Blob could not be retrieved using HID from list")
		}

		//Remove Blob from Commit List
		testListDelete := testList.Remove("blobToBeDeleted")
		testCommitDelete := testCommit.Update(testListDelete.Hash())
		services.PostCommit(testCommitDelete)

		//Check to make sure blob Does Not Exist in Commit List
		dneCommit, _ := services.GetCommit(commitHkid)
		dneList, _ := services.GetList(dneCommit.ListHash)
		_, found = dneList["blobToBeDeleted"]
		if found {
			b.Fatalf("Error: Blob incorrectly found in list")
		}
	}
}
Example #2
0
func (d dir) LookupList(name string, intr fs.Intr, nodeID fuse.NodeID) (fs.Node, fuse.Error) {
	log.Println("List Lookup")
	log.Printf("Request Name:\t%s\nRequest Node:\t%v\n", name, nodeID)
	select {
	case <-intr:
		return nil, fuse.EINTR
	default:
	}
	l, listErr := services.GetList(d.leaf.(objects.HCID))
	if listErr != nil {
		log.Printf("get list %s:", listErr)
		return nil, nil
	}
	listEntry, present := l[name] //go through list entries and is it maps to the string you passed in present == 1
	if !present {
		return nil, fuse.ENOENT
	}

	b, blobErr := services.GetBlob(listEntry.Hash.(objects.HCID))
	sizeBlob := 0
	if blobErr == nil {
		sizeBlob = len(b)
	}

	if listEntry.TypeString == "blob" {
		log.Println("Blob lookup")
		return file{
			contentHash: listEntry.Hash.(objects.HCID),
			permission:  d.permission,
			parent:      &d,
			name:        name,
			inode:       nodeID,
			size:        uint64(sizeBlob),
		}, nil
	}
	return dir{
		leaf:        listEntry.Hash,
		permission:  d.permission,
		contentType: listEntry.TypeString,
		parent:      &d,
		name:        name,
		openHandles: map[string]*openFileHandle{},
		inode:       generateInode(d.parent.inode, name),
	}, nil

}
Example #3
0
func crawlList(targHash objects.HCID) (err error) {
	firstList, listErr := services.GetList(targHash)
	if listErr != nil {
		return listErr
	}

	for _, entry := range firstList {
		newlistHash := target{
			typeString: entry.TypeString,
			hash:       entry.Hash,
		}
		if !queuedTargets[newlistHash.String()] {
			targetQueue <- newlistHash
			queuedTargets[newlistHash.String()] = true
		}
	}
	indexList(firstList)
	return nil
}
Example #4
0
func (d dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
	//log.Printf("ReadDir requested:\n\tName:%s", d.name)
	select {
	case <-intr:
		return nil, fuse.EINTR
	default:
	}
	var l objects.List
	var listErr error
	var dirDirs = []fuse.Dirent{}
	switch d.contentType {
	case "tag":
		//if d.content_type == "tag" {
		tags, tagErr := services.GetTags(d.leaf.(objects.HKID))
		if tagErr != nil {
			log.Printf("tag %s:", tagErr)
			return nil, fuse.ENOENT
		}
		for _, tag := range tags {
			name := tag.NameSegment
			enttype := fuse.DT_Dir
			switch tag.TypeString {
			case "blob":
				enttype = fuse.DT_File
				fallthrough

			case "list", "commit", "tag":
				dirDirs = append(dirDirs, fuse.Dirent{
					Inode: fs.GenerateDynamicInode(uint64(d.inode), name),
					Name:  name,
					Type:  enttype,
				})
			default:
			}
		}
		return dirDirs, nil
	case "commit":
		//} else if d.content_type == "commit" {
		c, CommitErr := services.GetCommit(d.leaf.(objects.HKID))
		if CommitErr != nil {
			log.Printf("commit %s:", CommitErr)
			return nil, fuse.ENOENT
		}
		l, listErr = services.GetList(c.ListHash)
		if listErr != nil {
			log.Printf("commit list %s:", listErr)
			return nil, fuse.ENOENT
		}
	case "list":
		l, listErr = services.GetList(d.leaf.(objects.HCID))
		if listErr != nil {
			log.Printf("list %s:", listErr)
			return nil, fuse.ENOENT
		}
	default:
		return nil, fuse.ENOENT
	}

	for name, entry := range l {
		if entry.TypeString == "blob" {
			appendToList := fuse.Dirent{
				Inode: fs.GenerateDynamicInode(uint64(d.inode), name),
				Name:  name,
				Type:  fuse.DT_File,
			}
			dirDirs = append(dirDirs, appendToList)
		} else {
			appendToList := fuse.Dirent{
				Inode: fs.GenerateDynamicInode(uint64(d.inode), name),
				Name:  name,
				Type:  fuse.DT_Dir}
			dirDirs = append(dirDirs, appendToList)
		}
	}

	//loop through openHandles
	for openHandle := range d.openHandles {
		inList := false
		for _, dirEntry := range dirDirs {
			if openHandle == dirEntry.Name {
				inList = true
				break
			}
		}
		if !inList {
			dirDirs = append(
				dirDirs,
				fuse.Dirent{
					Inode: fs.GenerateDynamicInode(uint64(d.inode), openHandle),
					Name:  openHandle,
					Type:  fuse.DT_Dir,
				})
		}
	}
	return dirDirs, nil
}
Example #5
0
func (d dir) LookupCommit(name string, intr fs.Intr, nodeID fuse.NodeID) (fs.Node, fuse.Error) {
	select {
	case <-intr:
		return nil, fuse.EINTR
	default:

	}
	ino := fuse.NodeID(1)
	if d.parent != nil {
		ino = generateInode(d.parent.inode, name)
	}
	c, CommitErr := services.GetCommit(d.leaf.(objects.HKID))

	if CommitErr != nil {
		return nil, fuse.EIO
		/*
			log.Printf("commit %s:", CommitErr)
			_, err := services.GetKey(d.leaf.(objects.HKID))
			perm := os.FileMode(0555)
			if err == nil {
				perm = 0777
			}
			return dir{
				permission:  perm,
				contentType: "commit",
				leaf:        d.leaf.(objects.HKID),
				parent:      &d,
				name:        name,
				openHandles: map[string]bool{},
				inode:       ino,
			}, nil
		*/
	}
	//get list hash
	l, listErr := services.GetList(c.ListHash) //l is the list object
	if listErr != nil {
		log.Printf("commit list retrieval error %s:", listErr)
		return nil, nil
	}

	listEntry, present := l[name] //go through list entries and is it maps to the string you passed in present == 1
	if !present {
		return nil, fuse.ENOENT
	}
	//getKey to figure out permissions of the child
	_, keyErr := services.GetKey(c.Hkid)
	//perm := fuse.Attr{Mode: 0555}//default read permissions
	perm := os.FileMode(0777)

	if keyErr != nil {
		log.Printf("error not nil; change file Mode %s:", keyErr)
		//perm =  fuse.Attr{Mode: 0755}
		perm = os.FileMode(0555)
	}

	if listEntry.TypeString == "blob" {
		b, blobErr := services.GetBlob(listEntry.Hash.(objects.HCID))
		sizeBlob := 0
		if blobErr == nil {
			sizeBlob = len(b)
		}
		return file{
			contentHash: listEntry.Hash.(objects.HCID),
			permission:  perm,
			name:        name,
			parent:      &d,
			inode:       nodeID,
			size:        uint64(sizeBlob),
		}, nil
	}

	ino = fuse.NodeID(1)
	if d.parent != nil {
		ino = generateInode(d.parent.inode, name)
	}

	return dir{
		leaf:        listEntry.Hash,
		permission:  perm,
		contentType: listEntry.TypeString,
		parent:      &d,
		name:        name,
		openHandles: map[string]*openFileHandle{},
		inode:       ino,
	}, nil

}
Example #6
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
	}
}
Example #7
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
}