From 2c260766864a56e10aa45c3b1782f640b21a0bac Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Thu, 20 Nov 2008 04:42:43 +0000 Subject: Nearly completed security/validation work. Still needs replication testing. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@719160 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_util.erl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/couchdb/couch_util.erl') diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index e6d6226b..d0f0c0b6 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -13,7 +13,7 @@ -module(couch_util). -export([start_driver/1]). --export([should_flush/0, should_flush/1]). +-export([should_flush/0, should_flush/1, to_existing_atom/1]). -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). -export([encodeBase64/1, decodeBase64/1, to_hex/1,parse_term/1,dict_find/3]). @@ -33,6 +33,16 @@ start_driver(LibDir) -> exit(erl_ddll:format_error(Error)) end. +% works like list_to_existing_atom, except can be list or binary and it +% gives you the original value instead of an error if no existing atom. +to_existing_atom(V) when is_list(V)-> + try list_to_existing_atom(V) catch _ -> V end; +to_existing_atom(V) when is_binary(V)-> + try list_to_existing_atom(?b2l(V)) catch _ -> V end; +to_existing_atom(V) when is_atom(V)-> + V. + + new_uuid() -> list_to_binary(to_hex(crypto:rand_bytes(16))). @@ -168,11 +178,7 @@ collate(A, B, Options) when is_binary(A), is_binary(B) -> [Result] = erlang:port_control(drv_port(), Operation, Bin), % Result is 0 for lt, 1 for eq and 2 for gt. Subtract 1 to return the % expected typical -1, 0, 1 - Result - 1; - -collate(A, B, _Options) -> - io:format("-----A,B:~p,~p~n", [A,B]), - throw({error, badtypes}). + Result - 1. should_flush() -> should_flush(?FLUSH_MAX_MEM). -- cgit v1.2.3