예제 #1
0
func (fs_obj fileSystem) Root() (fs.Node, fuse.Error) { //returns a directory
	log.Printf("Initializing filesystem:\n\tHKID: %s", fs_obj.hkid)
	_, err := services.GetKey(fs_obj.hkid)
	perm := os.FileMode(0555)
	if err == nil {
		perm = 0777
	}

	//return Repository{
	//	contents:   fs_obj.hkid,
	//	inode:      1,
	//	name:       "",
	//	parent:     nil,
	//	permission: perm,
	//}

	return dir{
		//path: "/",
		//trunc:        fs_obj.hkid,
		//branch:       fs_obj.hkid,
		permission:  perm,
		contentType: "commit",
		leaf:        fs_obj.hkid,
		parent:      nil,
		name:        "/",
		//openHandles:     map[string]bool{},
		openHandles: map[string]*openFileHandle{},
		inode:       1,
	}, nil
}
예제 #2
0
func TestLowLevel(t *testing.T) {
	indata := objects.Blob([]byte("TestPostData"))
	services.PostBlob(indata)
	blobhcid, err := objects.HcidFromHex(
		"ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2",
	)
	b, err := services.GetBlob(blobhcid)
	if !bytes.Equal(b.Hash(), blobhcid) {
		t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed
	}

	//6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85
	testhkid := objects.HkidFromDString(
		"6523237356270560228617783789728329416595512649112249373497830592"+
			"0722414168936112160694238047304378604753005642729767620850685191"+
			"88612732562106886379081213385", 10)
	testCommit := objects.NewCommit(b.Hash(), testhkid)
	services.PostCommit(testCommit)
	c, err := services.GetCommit(testhkid)
	if err != nil {
		t.Fatalf("Get Commit Fail: %s", err)
	} else if !bytes.Equal(c.Hkid, testhkid) {
		t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid)
	} else if !c.Verify() {
		t.Fatalf("Commit Signature Invalid.")
	}

	//ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312
	taghkid := objects.HkidFromDString(
		"4813315537186321970719165779488475377688633084782731170482174374"+
			"7256947679650787426167575073363006751150073195493002048627629373"+
			"76227751462258339344895829332", 10)
	lowlvlTag := objects.NewTag(
		objects.HID(b.Hash()),
		"blob",
		"testBlob",
		nil,
		taghkid,
	) //gen test tag
	services.PostTag(lowlvlTag)
	testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment)
	if err != nil {
		t.Fatalf("GetTag Fail. error: %s", err)
	} else if !bytes.Equal(testtag.Hkid, taghkid) {
		t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid)
	} else if !testtag.Verify() {
		t.Fatalf("GetTag Verify Fail")
	}

	prikey, err := services.GetKey(taghkid)
	if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() {
		t.Logf("GetKey Fail")
		t.Fail()
	}
}
예제 #3
0
func KeyLocalSeed() {
	HKIDstring := GetLocalSeed()
	h, er := objects.HkidFromHex(HKIDstring)
	if er != nil {
		log.Printf("local seed not valid hex /n")
	}
	_, err := services.GetKey(h)
	if err != nil {
		objects.HkidFromDString("65232373562705602286177837897283294165955126"+
			"49112249373497830592072241416893611216069423804730437860475300564272"+
			"976762085068519188612732562106886379081213385", 10)
	}
	return
}
예제 #4
0
func (d dir) LookupTag(name string, intr fs.Intr, nodeID fuse.NodeID) (fs.Node, fuse.Error) {
	select {
	case <-intr:
		return nil, fuse.EINTR
	default:
	}
	t, tagErr := services.GetTag(d.leaf.(objects.HKID), name) //leaf is HID
	// no blobs because blobs are for file structure

	if tagErr != nil {
		log.Printf("not a tag Err:%s", tagErr)
		return nil, fuse.ENOENT
	}
	//getKey to figure out permissions of the child
	_, keyErr := services.GetKey(t.Hkid)
	perm := os.FileMode(0555) //default read permissions
	if keyErr == nil {
		perm = os.FileMode(0755)
	} else {
		log.Printf("no private key %s:", keyErr)
	}
	if t.TypeString == "blob" {
		b, blobErr := services.GetBlob(t.HashBytes.(objects.HCID))
		sizeBlob := 0
		if blobErr == nil {
			sizeBlob = len(b)
		}
		return file{
			contentHash: t.HashBytes.(objects.HCID),
			permission:  perm,
			name:        name,
			parent:      &d,
			inode:       nodeID,
			size:        uint64(sizeBlob),
		}, nil
	}
	return dir{
		leaf:        t.HashBytes,
		permission:  perm,
		contentType: t.TypeString,
		parent:      &d,
		name:        name,
		openHandles: map[string]*openFileHandle{},
		inode:       generateInode(d.parent.inode, name),
	}, nil
}
예제 #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

}