diff options
author | Damien F. Katz <damien@apache.org> | 2009-07-17 21:33:41 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2009-07-17 21:33:41 +0000 |
commit | 91bf33fdc69c2087707795b8822b0fa7617f8709 (patch) | |
tree | f01ba98e03b77923d8256e9dd7cdca997ba06cf2 /src/couchdb/couch_file.erl | |
parent | 627562eef0290bcf07659f40d7ba85c333978ce6 (diff) |
Deterministic revids, MD5 checking of documents, added tracking of rev when an attachment is edited to allow attachment level replication.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@795232 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r-- | src/couchdb/couch_file.erl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index aec632fb..4c450163 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -25,6 +25,8 @@ -export([open/1, open/2, close/1, bytes/1, sync/1, append_binary/2,old_pread/3]). -export([append_term/2, pread_term/2, pread_iolist/2, write_header/2]). -export([pread_binary/2, read_header/1, truncate/2, upgrade_old_header/2]). +-export([append_term_md5/2, pread_iolist_md5/2, pread_binary_md5/2]). +-export([pread_term_md5/2]). -export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]). %%---------------------------------------------------------------------- @@ -67,6 +69,9 @@ open(Filepath, Options) -> append_term(Fd, Term) -> append_binary(Fd, term_to_binary(Term)). + +append_term_md5(Fd, Term) -> + append_binary_md5(Fd, term_to_binary(Term)). %%---------------------------------------------------------------------- @@ -80,6 +85,11 @@ append_term(Fd, Term) -> append_binary(Fd, Bin) -> Size = iolist_size(Bin), gen_server:call(Fd, {append_bin, [<<Size:32/integer>>, Bin]}, infinity). + +append_binary_md5(Fd, Bin) -> + Size = iolist_size(Bin), + gen_server:call(Fd, {append_bin, + [<<Size:32/integer>>, erlang:md5(Bin), Bin]}, infinity). %%---------------------------------------------------------------------- @@ -94,6 +104,10 @@ pread_term(Fd, Pos) -> {ok, Bin} = pread_binary(Fd, Pos), {ok, binary_to_term(Bin)}. +pread_term_md5(Fd, Pos) -> + {ok, Bin} = pread_binary_md5(Fd, Pos), + {ok, binary_to_term(Bin)}. + %%---------------------------------------------------------------------- %% Purpose: Reads a binrary from a file that was written with append_binary @@ -111,6 +125,17 @@ pread_iolist(Fd, Pos) -> <<Len:32/integer>> = iolist_to_binary(LenIolist), {ok, Iolist, _} = read_raw_iolist(Fd, NextPos, Len), {ok, Iolist}. + +pread_binary_md5(Fd, Pos) -> + {ok, L} = pread_iolist_md5(Fd, Pos), + {ok, iolist_to_binary(L)}. + +pread_iolist_md5(Fd, Pos) -> + {ok, LenIolist, NextPos} =read_raw_iolist(Fd, Pos, 20), + <<Len:32/integer, Md5/binary>> = iolist_to_binary(LenIolist), + {ok, Iolist, _} = read_raw_iolist(Fd, NextPos, Len), + Md5 = erlang:md5(Iolist), + {ok, Iolist}. read_raw_iolist(Fd, Pos, Len) -> BlockOffset = Pos rem ?SIZE_BLOCK, |