From 2f3b80f251032e3f9e927e21060ed5b44e4b4224 Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 26 Apr 2019 17:19:55 +0100 Subject: [PATCH] Why was I doing that, it looks bad. --- core/index.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/index.go b/core/index.go index 5635e53..dbcecb4 100644 --- a/core/index.go +++ b/core/index.go @@ -1,4 +1,5 @@ package core + import ( "crypto/sha256" "encoding/hex" @@ -53,13 +54,16 @@ func (in *Index) RemoveFile(path string) error { if err != nil { return err } - newFiles := in.Files[:0] - for _, v := range in.Files { - if filepath.Clean(v.File) != relPath { - newFiles = append(newFiles, v) + + i := 0 + for _, file := range in.Files { + if filepath.Clean(file.File) != relPath { + // Keep file, as it doesn't match + in.Files[i] = file + i++ } } - in.Files = newFiles + in.Files = in.Files[:i] return nil } @@ -175,6 +179,7 @@ func (in *Index) Refresh() error { } } in.Files = in.Files[:i] + in.resortIndex() return nil }