diff --git a/lib/mongo.rb b/lib/mongo.rb index 3fd3d58..aa5551e 100644 --- a/lib/mongo.rb +++ b/lib/mongo.rb @@ -50,4 +50,9 @@ require 'mongo/exceptions' require 'mongo/gridfs/grid_ext' require 'mongo/gridfs/grid' require 'mongo/gridfs/grid_io' +if RUBY_PLATFORM =~ /java/ + require 'mongo/gridfs/grid_io_fix' +end require 'mongo/gridfs/grid_file_system' + + diff --git a/lib/mongo/gridfs/grid_io_fix.rb b/lib/mongo/gridfs/grid_io_fix.rb new file mode 100644 index 0000000..91c2e4c --- /dev/null +++ b/lib/mongo/gridfs/grid_io_fix.rb @@ -0,0 +1,38 @@ +# encoding: UTF-8 + +# -- +# Copyright (C) 2008-2010 10gen Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ++ + +module Mongo + class GridIO + + # This fixes a comparson issue in JRuby 1.9 + def get_md5 + md5_command = BSON::OrderedHash.new + md5_command['filemd5'] = @files_id + md5_command['root'] = @fs_name + @server_md5 = @files.db.command(md5_command)['md5'] + if @safe + @client_md5 = @local_md5.hexdigest + if @local_md5.to_s != @server_md5.to_s + raise GridMD5Failure, "File on server failed MD5 check" + end + else + @server_md5 + end + end + end +end