Skip to content

Commit 68cadc1

Browse files
committed
minor: patch for JRuby 1.9 MD5 comparison bug
1 parent dd02b12 commit 68cadc1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/mongo.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ module Constants
5050
require 'mongo/gridfs/grid_ext'
5151
require 'mongo/gridfs/grid'
5252
require 'mongo/gridfs/grid_io'
53+
if RUBY_PLATFORM =~ /java/
54+
require 'mongo/gridfs/grid_io_fix'
55+
end
5356
require 'mongo/gridfs/grid_file_system'
57+
58+

lib/mongo/gridfs/grid_io_fix.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# encoding: UTF-8
2+
3+
# --
4+
# Copyright (C) 2008-2010 10gen Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
# ++
18+
19+
module Mongo
20+
class GridIO
21+
22+
# This fixes a comparson issue in JRuby 1.9
23+
def get_md5
24+
md5_command = BSON::OrderedHash.new
25+
md5_command['filemd5'] = @files_id
26+
md5_command['root'] = @fs_name
27+
@server_md5 = @files.db.command(md5_command)['md5']
28+
if @safe
29+
@client_md5 = @local_md5.hexdigest
30+
if @local_md5.to_s != @server_md5.to_s
31+
raise GridMD5Failure, "File on server failed MD5 check"
32+
end
33+
else
34+
@server_md5
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)