From a111f26fe618c5872b8b133bd2233fe6dafdf6c8 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 21 Jun 2019 20:56:27 -0700 Subject: [PATCH] avoid nil fix https://github.com/chrislusf/seaweedfs/issues/988 --- weed/filer2/filer_deletion.go | 2 +- weed/pb/filer_pb/filer_pb_helper.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/weed/filer2/filer_deletion.go b/weed/filer2/filer_deletion.go index 06e088de6..574be8555 100644 --- a/weed/filer2/filer_deletion.go +++ b/weed/filer2/filer_deletion.go @@ -78,7 +78,7 @@ func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) { for _, oldChunk := range oldEntry.Chunks { found := false for _, newChunk := range newEntry.Chunks { - if oldChunk.Fid.Equals(newChunk.Fid) { + if filer_pb.ChunkEquals(oldChunk, newChunk) { found = true break } diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.go index be59089dd..361b0f57d 100644 --- a/weed/pb/filer_pb/filer_pb_helper.go +++ b/weed/pb/filer_pb/filer_pb_helper.go @@ -21,8 +21,14 @@ func (fid *FileId) toFileId() string { return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String() } -func (fid *FileId) Equals(that *FileId) bool { - return fid.FileKey == that.FileKey && fid.VolumeId == that.VolumeId && fid.Cookie == that.Cookie +func ChunkEquals(this, that *FileChunk) bool { + if this.Fid == nil{ + this.Fid, _ = toFileId(this.FileId) + } + if that.Fid == nil{ + that.Fid, _ = toFileId(that.FileId) + } + return this.Fid.FileKey == that.Fid.FileKey && this.Fid.VolumeId == that.Fid.VolumeId && this.Fid.Cookie == that.Fid.Cookie } func BeforeEntrySerialization(chunks []*FileChunk) {