md5 for ruby gridfs too

This commit is contained in:
Mike Dirolf 2009-02-18 14:11:22 -05:00
parent ff68d3a734
commit 16c8170498
2 changed files with 26 additions and 2 deletions

View File

@ -67,6 +67,8 @@ module XGen
attr_accessor :lineno
attr_reader :md5
class << self
def exist?(db, name, root_collection=DEFAULT_ROOT_COLLECTION)
@ -142,6 +144,7 @@ module XGen
@aliases = doc['aliases']
@length = doc['length']
@metadata = doc['metadata']
@md5 = doc['md5']
else
@files_id = XGen::Mongo::Driver::ObjectID.new
@content_type = DEFAULT_CONTENT_TYPE
@ -370,7 +373,7 @@ module XGen
when IO::SEEK_SET
pos
end
new_chunk_number = (target_pos / @chunk_size).to_i
if new_chunk_number != @curr_chunk.chunk_number
@curr_chunk.save if @mode[0] == ?w
@ -405,7 +408,7 @@ module XGen
end
@db = nil
end
def closed?
@db == nil
end
@ -426,6 +429,10 @@ module XGen
h['uploadDate'] = @upload_date
h['aliases'] = @aliases
h['metadata'] = @metadata
md5_command = OrderedHash.new
md5_command['filemd5'] = @files_id
md5_command['root'] = @root
h['md5'] = @db.db_command(md5_command)['md5']
h
end

View File

@ -208,6 +208,23 @@ class GridStoreTest < Test::Unit::TestCase
}
end
def test_md5
GridStore.open(@@db, 'new-file', 'w') { |f| f.write("hello world\n")}
GridStore.open(@@db, 'new-file', 'r') { |f|
assert f.md5 == '6f5902ac237024bdd0c176cb93063dc4'
begin
f.md5 = 'cant do this'
fail "should have seen error"
rescue => ex
true
end
}
GridStore.open(@@db, 'new-file', 'w') {}
GridStore.open(@@db, 'new-file', 'r') { |f|
assert f.md5 == 'd41d8cd98f00b204e9800998ecf8427e'
}
end
def test_upload_date
now = Time.now
orig_file_upload_date = nil