switching everything over to []byte, abandoning merkletree for now

This commit is contained in:
2020-07-01 14:33:01 -04:00
parent e4ac7f70e6
commit 07bbb442ef
12 changed files with 215 additions and 82 deletions

View File

@@ -1,16 +1,21 @@
package database
import "time"
import (
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"time"
)
// Commit stores all the necessary information for a commit
type Commit struct {
CommitHash string // The hash of the commit (generated by hashing commit author name, time, the previous commit, and more? TODO: Not sure what else)
CommitHash []byte // The hash of the commit (generated by hashing commit author name, time, the previous commit, and more? TODO: Not sure what else)
TrackedFiles []File // All of the tracked files for this commit
Date string
Version string //User can tag a commit with a version number
Branch string //Branch this commit belongs to
Number string // The commit number
}
// CommitMeta stores the meta information about the commit
@@ -29,28 +34,44 @@ type File struct {
Name string
//BkpLocation string //TODO: Needed?
CurrentBase string
CurrentHash [16]byte `storm:"index,unique"`
Hash []byte `storm:"index,unique"` // with []byte can't use sha256.sum256 since that is [32]byte, so everything done manually.
CreatedAt time.Time
Unique string
Version float64
NoCompress bool // Whether or not to compress this file
}
// CalculateHash creates a hash for the file
func (f *File) CalculateHash() error {
file, err := os.Open(f.Path)
if err != nil {
return fmt.Errorf("unable to open file: %s err: %s", f.Path, err)
}
fileContents, err := ioutil.ReadAll(file)
if err != nil {
return fmt.Errorf("unable to read contents of file: %s err: %s", f.Path, err)
}
hash := sha256.New()
hash.Write(fileContents)
f.Hash = hash.Sum(nil)
return nil
}
type FileIndex struct {
ID int `storm:"id,increment"`
FileID int `storm:"index"`
FileHash [16]byte `storm:"index,unique"`
FileHash [32]byte `storm:"index,unique"`
Index []byte
Length int64
}
// DiffObject store the information for each diff that is made
type DiffObject struct {
ID int `storm:"id,increment"`
Target string `storm:"index"`
DiffObject string `storm:"index"`
TargetHash [16]byte `storm:"index"`
DiffObjectHash [16]byte `storm:"index"`
ID int `storm:"id,increment"`
Target string `storm:"index"`
DiffObject string `storm:"index"`
TargetHash []byte `storm:"index"`
DiffObjectHash []byte `storm:"index"`
//Watching string //name of the file being watched
DiffPath string //path of the diff/patch //path would be .gvc/hashofcommit/
//Label string //store a comment if the user wants to (user written)