moving manager over to the engine for now
This commit is contained in:
@@ -3,13 +3,11 @@ package engine
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/deranjer/gvc/common/database"
|
||||
)
|
||||
@@ -91,30 +89,14 @@ func InitiateDirectory(directory string) {
|
||||
}
|
||||
}
|
||||
|
||||
// CreateInitialCommit copies the files over and compresses them if they are not in the NoCompress struct
|
||||
func CreateInitialCommit(fileList []database.File, commitMessage string) error { // ONLY HAPPENS FOR MASTER I THINK, SO NO BRANCH NEEDED
|
||||
//Need to deduplicate so we aren't storing duplicates of files, storing all the files in one folder won't work, will need something like git
|
||||
//For initial commit no changes are made to files, so don't store anything, just save the list so you can send to server
|
||||
var initialCommit database.Commit
|
||||
initialCommit.Branch = "master"
|
||||
|
||||
//var hashList [][]byte
|
||||
hasher := sha256.New()
|
||||
for _, file := range fileList {
|
||||
var err error
|
||||
err = file.CalculateHash()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to calculate hash for file: %s with error: %s", file.Path, err)
|
||||
}
|
||||
hasher.Write(file.Hash[:])
|
||||
func ConvertFileForStorage(file *database.File, folder string) error {
|
||||
fileBytes, err := ioutil.ReadFile(file.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
time := time.Now() // Adding the metadata to the hash
|
||||
hasher.Write([]byte(commitMessage + time.String()))
|
||||
hashBytes := hasher.Sum(nil) // Getting the hash bytes
|
||||
fullHash := hex.EncodeToString(hashBytes)
|
||||
fmt.Println("Commit hash: ", fullHash)
|
||||
initialCommit.CommitHash = hashBytes
|
||||
fmt.Println("REMOVE: ", fileBytes)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func IsDirectory(path string) (bool, error) {
|
||||
|
Reference in New Issue
Block a user