From 2e4ddb667f5ada81e2e67dc50401209b312ae428 Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 26 Apr 2019 18:45:59 +0100 Subject: [PATCH] Important to keep the index sorted because git diffs --- core/index.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/core/index.go b/core/index.go index 4c87fb6..3ae34f1 100644 --- a/core/index.go +++ b/core/index.go @@ -77,8 +77,8 @@ func (in *Index) resortIndex() { }) } -// UpdateFile calculates the hash for a given path and updates it in the index -func (in *Index) UpdateFile(path string) error { +// updateFile calculates the hash for a given path and updates it in the index +func (in *Index) updateFile(path string) error { f, err := os.Open(path) if err != nil { return err @@ -176,7 +176,7 @@ func (in *Index) Refresh() error { return nil } - return in.UpdateFile(path) + return in.updateFile(path) }) if err != nil { return err @@ -186,7 +186,7 @@ func (in *Index) Refresh() error { i := 0 for _, file := range in.Files { if file.fileExistsTemp { - // Keep file if it exists (already checked in UpdateFile) + // Keep file if it exists (already checked in updateFile) in.Files[i] = file i++ } @@ -197,6 +197,16 @@ func (in *Index) Refresh() error { return nil } +// RefreshFile calculates the hash for a given path and updates it in the index (also sorts the index) +func (in *Index) RefreshFile(path string) error { + err := in.updateFile(path) + if err != nil { + return err + } + in.resortIndex() + return nil +} + // Write saves the index file func (in Index) Write() error { f, err := os.Create(in.indexFile)