nickva commented on code in PR #5611:
URL: https://github.com/apache/couchdb/pull/5611#discussion_r2257368905


##########
src/couch/src/couch_bt_engine_header.erl:
##########
@@ -204,17 +204,16 @@ upgrade_tuple(Old) when is_record(Old, db_header) ->
     Old;
 upgrade_tuple(Old) when is_tuple(Old) ->
     NewSize = record_info(size, db_header),
-    if
-        tuple_size(Old) < NewSize -> ok;
-        true -> erlang:error({invalid_header_size, Old})
-    end,
-    {_, New} = lists:foldl(
-        fun(Val, {Idx, Hdr}) ->
-            {Idx + 1, setelement(Idx, Hdr, Val)}
+    Upgrade = tuple_size(Old) < NewSize,
+    ProhibitDowngrade = config:get_boolean("couchdb", "prohibit_downgrade", 
true),
+    OldKVs =
+        case {Upgrade, ProhibitDowngrade} of
+            {true, AnyBool} when is_boolean(AnyBool) -> tuple_to_list(Old);
+            {false, true} -> error({invalid_header_size, Old});
+            {false, false} -> lists:sublist(tuple_to_list(Old), NewSize)

Review Comment:
   yeah, and we had handled the `==` as well anyway in the no-op clause of the 
function:
   
   ```
   upgrade_tuple(Old) when is_record(Old, db_header) ->
       Old;
   ```
   
   So only `>` remains and that seems to work like:
   
   ```
   > lists:sublist(tuple_to_list({rec,a,b}), 2).
   [rec,a]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to