From 8d2e9c8a10cb6a53874e47a30b63e194f12d80fb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Nov 2011 22:04:47 +0000 Subject: [PATCH] admin (list_fids,each_fid): convert integer fields to integers fid, devcount, length are all integers, so ensure they're actual Integer (Fixnum/Bignum) objects. --- lib/mogilefs/admin.rb | 16 +++++++++++----- test/test_admin.rb | 24 ++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index 6b63a6b..eeb58ba 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -84,8 +84,9 @@ class MogileFS::Admin < MogileFS::Client # "key"=>"new_new_key"}] def list_fids(from_fid, to_fid) + to_i = { "fid" => true, "devcount" => true, "length" => true } clean('fid_count', 'fid_', - @backend.list_fids(:from => from_fid, :to => to_fid)) + @backend.list_fids(:from => from_fid, :to => to_fid), true, to_i) end ## @@ -327,13 +328,18 @@ class MogileFS::Admin < MogileFS::Client # "altip"=>"", # "altmask"=>""}] - def clean(count, prefix, res, underscore = true) + def clean(count, prefix, res, underscore = true, to_i = []) underscore = underscore ? '_' : '' + keys = res.keys (1..res[count].to_i).map do |i| - dev = res.select { |k,_| k =~ /^#{prefix}#{i}#{underscore}/ }.map do |k,v| - [k.sub(/^#{prefix}#{i}#{underscore}/, ''), v] + re = /^#{prefix}#{i}#{underscore}/ + row = {} + keys.grep(re).each do |k| + v = res[k] + k = k.sub(re, "").freeze + row[k] = to_i.include?(k) ? v.to_i : v end - Hash[*dev.flatten] + row end end diff --git a/test/test_admin.rb b/test/test_admin.rb index a7b0963..c9b128c 100644 --- a/test/test_admin.rb +++ b/test/test_admin.rb @@ -64,17 +64,17 @@ class TestMogileFS__Admin < TestMogileFS @client.each_fid { |fid| fids << fid } expected = [ - { "fid" => "99", + { "fid" => 99, "class" => "normal", "domain" => "test", - "devcount" => "2", - "length" => "4", + "devcount" => 2, + "length" => 4, "key" => "file_key" }, - { "fid" => "182", + { "fid" => 182, "class" => "normal", - "devcount" => "2", + "devcount" => 2, "domain" => "test", - "length" => "9", + "length" => 9, "key" => "new_new_key" }, ] @@ -135,17 +135,17 @@ class TestMogileFS__Admin < TestMogileFS } expected = [ - { "fid" => "99", + { "fid" => 99, "class" => "normal", "domain" => "test", - "devcount" => "2", - "length" => "4", + "devcount" => 2, + "length" => 4, "key" => "file_key" }, - { "fid" => "82", + { "fid" => 82, "class" => "normal", - "devcount" => "2", + "devcount" => 2, "domain" => "test", - "length" => "9", + "length" => 9, "key" => "new_new_key" }, ] -- 2.11.4.GIT