Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Allow updating metadata with fewer keys

Neeraj Gupta9132fc5ec8b5
diff --git a/server/pkg/controller/file.go b/server/pkg/controller/file.go
index c001089d4d..20a6c2d34c 100644
--- a/server/pkg/controller/file.go
+++ b/server/pkg/controller/file.go
@@ -633,7 +633,11 @@ 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, "")
}
- if existingMetadata != nil && (existingMetadata.Version != updateMMdRequest.MagicMetadata.Version || existingMetadata.Count > updateMMdRequest.MagicMetadata.Count) {
+ 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.
+ if existingMetadata != nil && (existingMetadata.Version != updateMMdRequest.MagicMetadata.Version || oldToNewCountDiff > 2) {
log.WithFields(log.Fields{
"existing_count": existingMetadata.Count,
"existing_version": existingMetadata.Version,