Permalink
Browse files

Add util support for checking node architecture.

  • Loading branch information...
1 parent 3702a7a commit 82ee22da2e3d8711cdd4e9115da3d5c80ef8317e @massung massung committed Sep 7, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/riak_core_util.erl
View
@@ -37,7 +37,8 @@
start_app_deps/1,
build_tree/3,
rpc_every_member/4,
- rpc_every_member_ann/4]).
+ rpc_every_member_ann/4,
+ is_arch/1]).
@jonmeredith

jonmeredith Sep 7, 2011

Contributor

Minor whitespace issue - are you using emacs electric indent or in Andrew's vi camp?

@massung

massung Sep 7, 2011

Contributor

Emacs, with tabs -> spaces. Odd, there's definitely a tab in there as I open it up now. (setq indent-tabs-mode nil) is set in my .emacs file. Is there a better way to do this?

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
@@ -262,6 +263,19 @@ build_tree(N, Nodes, Opts) ->
end, {[], tl(Expand)}, Nodes),
orddict:from_list(Tree).
+%% Returns a forced-lowercase architecture for this node
+-spec get_arch () -> string().
+get_arch () -> string:to_lower(erlang:system_info(system_architecture)).
+
+%% Checks if this node is of a given architecture
+-spec is_arch (atom()) -> boolean().
+is_arch (linux) -> string:str(get_arch(),"linux") > 0;
+is_arch (darwin) -> string:str(get_arch(),"darwin") > 0;
+is_arch (sunos) -> string:str(get_arch(),"sunos") > 0;
+is_arch (osx) -> is_arch(darwin);
+is_arch (solaris) -> is_arch(sunos);
+is_arch (_) -> false.
+
%% ===================================================================
%% EUnit tests
%% ===================================================================

0 comments on commit 82ee22d

Please sign in to comment.