From b132cb893f866dfa7f7d2dbb34588390aa2d013e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 3 Nov 2020 12:21:42 -0800 Subject: [PATCH] in case some chunks modified earliar are added later --- weed/filesys/file.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/weed/filesys/file.go b/weed/filesys/file.go index 4662c23db..de788b364 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -282,15 +282,37 @@ func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, er return entry, nil } +func lessThan(a, b *filer_pb.FileChunk) bool { + if a.Mtime == b.Mtime { + return a.Fid.FileKey < b.Fid.FileKey + } + return a.Mtime < b.Mtime +} + func (file *File) addChunks(chunks []*filer_pb.FileChunk) { - sort.Slice(chunks, func(i, j int) bool { - if chunks[i].Mtime == chunks[j].Mtime { - return chunks[i].Fid.FileKey < chunks[j].Fid.FileKey + // find the earliest incoming chunk + newChunks := chunks + earliestChunk := newChunks[0] + for i:=1;i