making changes to common library, starting to integrate database functions

This commit is contained in:
2020-06-11 17:24:35 -04:00
parent 0ecb0b96ce
commit d335549fd5
15 changed files with 317 additions and 145 deletions

View File

@@ -1,6 +1,8 @@
package engine
import (
"fmt"
logger "github.com/apsdehal/go-logger"
)
@@ -23,9 +25,9 @@ func NewPatcher(logger *logger.Logger, KEYFOLDER, DOWNLOADFOLDER, SYNCFOLDER, TH
// last save is the file you want to get.
func (p *Patcher) PatchFromFile(filePath, patchPath, restorePath string) error {
if subject, err := openFile(filePath); err != nil {
p.ErrorF("error on subject file: ", err)
return fmt.Errorf("error on subject file: ", err)
} else if patch, err := openFile(patchPath); err != nil {
p.ErrorF("error on patch file: ", err)
return fmt.Errorf("error on patch file: ", err)
} else {
return p.applyPatch(subject, patch, restorePath)
}
@@ -36,14 +38,12 @@ func (p *Patcher) PatchFromFile(filePath, patchPath, restorePath string) error {
// be upgraded for different patching algorithms
func (p *Patcher) applyPatch(subject, patch []byte, restorePath string) error {
if delta, err := decompressDelta(patch); err != nil {
p.ErrorF("error decompressing delta", err)
return fmt.Errorf("error decompressing delta", err)
} else {
if appliedBytes, err := applyPatchToFile(subject, delta); err != nil {
p.ErrorF("error applying delta to original file", err)
return err
return fmt.Errorf("error applying delta to original file", err)
} else if err := writeFile(restorePath, appliedBytes); err != nil {
p.ErrorF("error writing patchedFile", err)
return err
return fmt.Errorf("error writing patchedFile", err)
} else {
return nil
}