From 222887489820d398a5593bb6498c3c7096b4b794 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:22:02 +0530 Subject: [PATCH] [Fix] Handle case when existing metadata is null --- server/pkg/controller/file.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/pkg/controller/file.go b/server/pkg/controller/file.go index 20a6c2d34c..f14ea34305 100644 --- a/server/pkg/controller/file.go +++ b/server/pkg/controller/file.go @@ -633,7 +633,10 @@ func (c *FileController) validateUpdateMetadataRequest(ctx *gin.Context, req ent }).Error("can't update magic metadata for file which isn't owned by use") return stacktrace.Propagate(ente.ErrPermissionDenied, "") } - oldToNewCountDiff := existingMetadata.Count - updateMMdRequest.MagicMetadata.Count + oldToNewCountDiff := 0 + if existingMetadata != nil { + oldToNewCountDiff = existingMetadata.Count - updateMMdRequest.MagicMetadata.Count + } // Return an error if there is a version mismatch with the previous metadata // or if the new metadata contains an unexpectedly lower number of keys // (oldToNewCountDiff difference is > 2), which may indicate potential data loss due to potentially buggy client.