making changes to common library, starting to integrate database functions
This commit is contained in:
		@@ -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
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user