@@ -33,6 +33,13 @@ func NewFileHandleInSnapshot(path, snapName string) (*FileHandle, error) {
3333 return newFileHandle (ds .ConvertToSnapPath (path , snapName ))
3434}
3535
36+ // NewFileHandleInSnapshotPart is the flipped, partially applied version of 'NewFileHandleInSnapshot'
37+ func NewFileHandleInSnapshotPart (snapName string ) func (string ) (* FileHandle , error ) {
38+ return func (path string ) (* FileHandle , error ) {
39+ return NewFileHandleInSnapshot (path , snapName )
40+ }
41+ }
42+
3643func newFileHandle (path string ) (* FileHandle , error ) {
3744 fi , err := os .Stat (path )
3845 if err != nil {
@@ -161,13 +168,12 @@ func (fh *FileHandle) CopyAs(path string) (err error) {
161168// * deleted entries are inserted
162169// * inserted entries are removed
163170func (fh * FileHandle ) Patch (deltas Deltas ) error {
164- var err error
165171
166172 // verify the equal parts from the deltas are the same as in the given file
167173 // returns a error if not
168174 verifyDeltasAreApplicable := func () error {
169- var f * os.File
170- if f , err = os . Open ( fh . Path ); err != nil {
175+ f , err := os .Open ( fh . Path )
176+ if err != nil {
171177 return fmt .Errorf ("open file: '%s' - %s" , fh .Name , err .Error ())
172178 }
173179 defer f .Close ()
@@ -190,14 +196,15 @@ func (fh *FileHandle) Patch(deltas Deltas) error {
190196
191197 // apply the deltas to a given file
192198 applyDeltasTo := func (dstPath string ) error {
193- var src , dst * os.File
194199 // open src / dst
195- if src , err = os .Open (fh .Path ); err != nil {
200+ src , err := os .Open (fh .Path )
201+ if err != nil {
196202 return fmt .Errorf ("unable to open src-file: '%s' - %s" , fh .Path , err .Error ())
197203 }
198204 defer src .Close ()
199205
200- if dst , err = os .Create (dstPath ); err != nil {
206+ dst , err := os .Create (dstPath )
207+ if err != nil {
201208 return fmt .Errorf ("unable to open dst-file: '%s' - %s" , dstPath , err .Error ())
202209 }
203210 defer func () {
@@ -267,12 +274,13 @@ func (fh *FileHandle) Patch(deltas Deltas) error {
267274 }
268275
269276 if err := os .Rename (patchWorkFilePath , fh .Path ); err != nil {
270- return fmt .Errorf ("unable to rename patch file to orginal file - %s" , err .Error ())
277+ return fmt .Errorf ("unable to rename patch file to original file - %s" , err .Error ())
271278 }
272279
273280 return nil
274281}
275282
283+ // MoveToBackup moves the file in the backup location
276284func (fh * FileHandle ) MoveToBackup () error {
277285 backupDir := fmt .Sprintf ("%s/.zsd" , filepath .Dir (fh .Path ))
278286
@@ -296,7 +304,7 @@ func (fh *FileHandle) MoveToBackup() error {
296304 return os .Rename (fh .Path , backupFilePath )
297305}
298306
299- // FileHasChangedFunGen to create a FileHasChangedFunc
307+ // FileHasChangedFuncGen to create a FileHasChangedFunc
300308type FileHasChangedFuncGen func (* FileHandle ) FileHasChangedFunc
301309
302310// FileHasChangedFunc to detect if a file has changed
@@ -329,7 +337,7 @@ func NewFileHasChangedFuncGenByName(method string) (FileHasChangedFuncGen, error
329337 return CompareFileBySizeAndModTime (actual )
330338 }, nil
331339 default :
332- return nil , fmt .Errorf ("no such compare method: '%s' - avaliable : 'size+modTime', 'size', 'md5'" , method )
340+ return nil , fmt .Errorf ("no such compare method: '%s' - available : 'size+modTime', 'size', 'md5'" , method )
333341 }
334342}
335343
0 commit comments