adding decompress

This commit is contained in:
2020-07-07 15:03:33 -04:00
parent c07e09d155
commit ebd6e095f7
77 changed files with 185 additions and 50 deletions

View File

@@ -149,8 +149,12 @@ func (m *Manager) AddFileToRepo(relFilePath string) error {
//DELAYED: this feature affects only large files and user experience. It can wait.
relFilePath = strings.TrimSpace(relFilePath) //purging any odd spaces TODO: Make sure not needed
var tmpFile database.File
filename := filepath.Base(relFilePath)
var hash []byte
tmpFile.Path = relFilePath
filename := filepath.Base(tmpFile.Path)
alreadyTracked := m.dB.CheckIfFileCurrentlyMonitored(tmpFile.Path)
if alreadyTracked {
return fmt.Errorf("file already found in tracked files, not adding: %s", relFilePath)
}
//check that the file actually exists (currently done by client/server)
// if filename, err = VerifySrcFile(relFilePath); err != nil {
// //there was no source file or it was not recognisable as a file
@@ -158,19 +162,12 @@ func (m *Manager) AddFileToRepo(relFilePath string) error {
// }
//generate a unique file name from the hash and the moment it was created
//a sampled (and therefore) fast, hash of the file for 'uniqueness'
if hash, err = UniqueFileHash(relFilePath); err != nil {
if err = tmpFile.CalculateHash(); err != nil { //creates the hash for the file
return err
}
m.Info().Msgf("Hash generated for file: %s hash: %s", relFilePath, hex.EncodeToString(hash))
alreadyTracked := m.dB.CheckIfFileCurrentlyMonitored(relFilePath)
if alreadyTracked {
return fmt.Errorf("file already found in tracked files, not adding: %s", relFilePath)
}
tmpFile = database.File{}
tmpFile.Hash = hash
m.Info().Msgf("Hash generated for file: %s hash: %s", tmpFile.Path, hex.EncodeToString(tmpFile.Hash))
tmpFile.Name = filename
tmpFile.Path = relFilePath
tmpFile.CreatedAt = time.Now()
tmpFile.Unique = hex.EncodeToString([]byte(filename)) + "_" + hex.EncodeToString((tmpFile.Hash)) + "_" + strconv.FormatInt(tmpFile.CreatedAt.Unix(), 10) + "_" + filename
//tmpFile.BkpLocation = filepath.Join(m.SyncFolder, tmpFile.Unique)
@@ -207,6 +204,7 @@ func (m *Manager) prepareDatabaseForFile(tmpFile database.File) (int, error) {
// BeginCommit starts the commit process
func (m *Manager) BeginCommit(branch string, commitMessage string) error {
fmt.Println("Beginning Commit on Branch: ", branch)
trackedFiles, err := m.dB.RetrieveTrackedFiles()
if err != nil {
return err
@@ -214,6 +212,15 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
if len(trackedFiles) == 0 {
return fmt.Errorf("no files show as tracked in repo, cannot commit, aborting...")
}
commit, err := m.dB.FetchLastCommitOnBranch(branch) //Check for previous commits
if err != nil {
m.Info().Msgf("unable to fetch last commit on branch, assuming first commit on branch", err)
err := m.CreateInitialCommit(trackedFiles, branch, commitMessage) // Create the initial commit
if err != nil {
m.Err(err).Msgf("unable to create initial commit: %s", err)
return err
}
}
var filesToDiff []database.File // Contains the list of files that have changed
for _, trackedFile := range trackedFiles {
fmt.Println("Working on file: ", trackedFile.Path)
@@ -226,7 +233,6 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
fmt.Printf("unable to stat tracked file: %s error: %s\n", currentFile.Name(), err)
continue
}
currentFileHash, err := UniqueFileHash(trackedFile.Path)
if err != nil {
fmt.Printf("unable to create hash for file: %s error: %s\n", currentFile.Name(), err)
@@ -242,14 +248,10 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
//diffChannel := make(chan database.DiffObject)
//diffContext := context.Background()
//m.WaitGroup.Add(2)
commit, err := m.dB.FetchLastCommitOnBranch(branch)
if err != nil {
m.Info().Msgf("unable to fetch last commit on branch, assuming first commit on branch", err)
err := m.CreateInitialCommit(filesToDiff, commitMessage)
if err != nil {
m.Err(err).Msgf("unable to create initial commit: %s", err)
return err
}
fmt.Println("Changed Files: ", filesToDiff)
if len(filesToDiff) == 0 {
m.Info().Msgf("No changed files found to commit on branch: %s", branch)
return fmt.Errorf("no changed files, cannot commit on branch: %s", branch)
}
fmt.Println("COMMIT: ", commit.CommitHash)
return nil