Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 78EE41097C for ; Thu, 3 Oct 2013 14:12:17 +0000 (UTC) Received: (qmail 18373 invoked by uid 500); 3 Oct 2013 14:11:30 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 17140 invoked by uid 500); 3 Oct 2013 14:11:07 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 16671 invoked by uid 99); 3 Oct 2013 14:11:03 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Oct 2013 14:11:03 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5C96C90E6F2; Thu, 3 Oct 2013 14:11:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jan@apache.org To: commits@couchdb.apache.org Date: Thu, 03 Oct 2013 14:11:43 -0000 Message-Id: <7ef2a84cb53143f09cef4b91d0c81fce@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [43/50] [abbrv] git commit: updated refs/heads/1867-feature-plugins to 95d6e35 only install plugins if their CouchDB version matches the target couch Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/075c8117 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/075c8117 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/075c8117 Branch: refs/heads/1867-feature-plugins Commit: 075c8117fe7e77156d7261421f86d6d9bda6897c Parents: e575751 Author: Jan Lehnardt Authored: Fri Aug 2 23:09:01 2013 +0200 Committer: Jan Lehnardt Committed: Thu Oct 3 16:08:37 2013 +0200 ---------------------------------------------------------------------- share/www/plugins.html | 10 ++++---- src/couch_plugins/src/couch_plugins.erl | 29 ++++++++++++++++------ src/couch_plugins/src/couch_plugins_httpd.erl | 18 ++++++++------ 3 files changed, 37 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/075c8117/share/www/plugins.html ---------------------------------------------------------------------- diff --git a/share/www/plugins.html b/share/www/plugins.html index e7ffc26..7f8da53 100644 --- a/share/www/plugins.html +++ b/share/www/plugins.html @@ -33,16 +33,16 @@ specific language governing permissions and limitations under the License.

GeoCouch

-

Version: couchdb1.2.x_v0.3.0-11-g4ea0bea

+

Version: couchdb1.2.x_v0.3.0-11-g66e6219

Author: Volker Mische

Available Erlang Versions:

    -
  • R15B01
  • +
  • CouchDB 1.4.0-XXX R15B01

- +

@@ -52,11 +52,11 @@ specific language governing permissions and limitations under the License.

Available Erlang Versions:

    -
  • R15B01
  • +
  • CouchDB 1.4.0-XXX R15B01

- +

http://git-wip-us.apache.org/repos/asf/couchdb/blob/075c8117/src/couch_plugins/src/couch_plugins.erl ---------------------------------------------------------------------- diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl index 3463d3d..507f114 100644 --- a/src/couch_plugins/src/couch_plugins.erl +++ b/src/couch_plugins/src/couch_plugins.erl @@ -207,18 +207,25 @@ download({Name, _BaseUrl, Version, _Checksums}=Plugin) -> -spec verify_checksum(string(), list()) -> ok | {error, string()}. verify_checksum(Filename, Checksums) -> - OTPRelease = erlang:system_info(otp_release), - case proplists:get_value(OTPRelease, Checksums) of + CouchDBVersion = couchdb_version(), + case proplists:get_value(CouchDBVersion, Checksums) of undefined -> - ?LOG_ERROR("[couch_plugins] Can't find checksum for OTP Release '~s'", [OTPRelease]), - {error, no_checksum}; - Checksum -> - do_verify_checksum(Filename, Checksum) + ?LOG_ERROR("[couch_plugins] Can't find checksum for CouchDB Version '~s'", [CouchDBVersion]), + {error, no_couchdb_checksum}; + OTPChecksum -> + OTPRelease = erlang:system_info(otp_release), + case proplists:get_value(OTPRelease, OTPChecksum) of + undefined -> + ?LOG_ERROR("[couch_plugins] Can't find checksum for Erlang Version '~s'", [OTPRelease]), + {error, no_erlang_checksum}; + Checksum -> + do_verify_checksum(Filename, Checksum) + end end. -spec do_verify_checksum(string(), string()) -> ok | {error, string()}. do_verify_checksum(Filename, Checksum) -> - ?LOG_DEBUG("Filename: ~s", [Filename]), + ?LOG_DEBUG("Checking Filename: ~s", [Filename]), case file:read_file(Filename) of {ok, Data} -> ComputedChecksum = binary_to_list(base64:encode(crypto:sha(Data))), @@ -246,7 +253,8 @@ get_filename(Name, Version) -> get_file_slug(Name, Version) -> % OtpRelease does not include patch levels like the -1 in R15B03-1 OTPRelease = erlang:system_info(otp_release), - Name ++ "-" ++ Version ++ "-" ++ OTPRelease. + CouchDBVersion = couchdb_version(), + string:join([Name, Version, OTPRelease, CouchDBVersion], "-"). -spec file_exists(string()) -> boolean(). file_exists(Filename) -> @@ -255,6 +263,11 @@ file_exists(Filename) -> does_file_exist({error, enoent}) -> false; does_file_exist(_Else) -> true. +couchdb_version() -> + %% strip git hash from version string + [Version|_Rest] = string:tokens(couch_server:get_version(), "+"), + Version. + % installing a plugin: % - POST /_plugins -d {plugin-def} % - get plugin definition http://git-wip-us.apache.org/repos/asf/couchdb/blob/075c8117/src/couch_plugins/src/couch_plugins_httpd.erl ---------------------------------------------------------------------- diff --git a/src/couch_plugins/src/couch_plugins_httpd.erl b/src/couch_plugins/src/couch_plugins_httpd.erl index 7a99cd1..d292ec6 100644 --- a/src/couch_plugins/src/couch_plugins_httpd.erl +++ b/src/couch_plugins/src/couch_plugins_httpd.erl @@ -25,12 +25,9 @@ handle_req(#httpd{method='POST'}=Req) -> Version = binary_to_list(couch_util:get_value(<<"version">>, PluginSpec)), Delete = couch_util:get_value(<<"delete">>, PluginSpec), {Checksums0} = couch_util:get_value(<<"checksums">>, PluginSpec), - Checksums = lists:map(fun({K, V}) -> - {binary_to_list(K), binary_to_list(V)} - end, Checksums0), + Checksums = parse_checksums(Checksums0), + Plugin = {Name, Url, Version, Checksums}, - ?LOG_DEBUG("~p", [Plugin]), - ?LOG_DEBUG("~p", [Delete]), case do_install(Delete, Plugin) of ok -> couch_httpd:send_json(Req, 202, {[{ok, true}]}); @@ -41,7 +38,14 @@ handle_req(#httpd{method='POST'}=Req) -> handle_req(Req) -> couch_httpd:send_method_not_allowed(Req, "POST"). -do_install(false, Plugin)-> +do_install(false, Plugin) -> couch_plugins:install(Plugin); -do_install(true, Plugin)-> +do_install(true, Plugin) -> couch_plugins:uninstall(Plugin). + +parse_checksums(Checksums) -> + lists:map(fun({K, {V}}) -> + {binary_to_list(K), parse_checksums(V)}; + ({K, V}) -> + {binary_to_list(K), binary_to_list(V)} + end, Checksums). \ No newline at end of file