You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2023/05/06 14:05:48 UTC

[couchdb] 03/05: make legacy checksums a compile-time option

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch remove-md5-more
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f16953b26414f915b0d400f62cde1dfdd6f3c50c
Author: Robert Newson <rn...@apache.org>
AuthorDate: Sat May 6 14:36:38 2023 +0100

    make legacy checksums a compile-time option
---
 src/couch/src/couch_file.erl | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index 315f3a795..0a9aaf49c 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -864,11 +864,11 @@ verify_checksum(Fd, Pos, IoList, Checksum) ->
 
 verify_checksum(Data, ExpectedChecksum) ->
     Bin = iolist_to_binary(Data),
-    case ExpectedChecksum == exxhash:xxhash128(Bin) of
+    case ExpectedChecksum == checksum(Bin) of
         true ->
             true;
         false ->
-            case ExpectedChecksum == couch_hash:md5_hash(Data) of
+            case ExpectedChecksum == legacy_checksum(Data) of
                 true ->
                     couch_stats:increment_counter([couch_file, old_checksums]),
                     true;
@@ -877,6 +877,18 @@ verify_checksum(Data, ExpectedChecksum) ->
             end
     end.
 
+checksum(Bin) when is_binary(Bin) ->
+    exxhash:xxhash128(Bin).
+
+-ifdef(NO_MD5).
+legacy_checksum(Bin) when is_binary(Bin) ->
+    true.
+-else.
+legacy_checksum(Bin) when is_binary(Bin) ->
+    couch_hash:md5_hash(Bin).
+-endif.
+
+
 report_checksum_error(Fd, Pos) ->
     couch_log:emergency("File corruption in ~p at position ~B", [Fd, Pos]),
     exit({file_corruption, <<"file corruption">>}).