mogilefs-client.git  about / heads / tags
MogileFS client library for Ruby
blob 0aa676d311262d5a6387115851518ffb32720f02 704 bytes (raw)
$ git show HEAD:lib/mogilefs/paths_size.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
# -*- encoding: binary -*-
# This is only a hack for old MogileFS installs that didn't have file_info
require "net/http"
require "uri"
module MogileFS::PathsSize
  def self.call(paths)
    errors = {}
    paths.each do |path|
      uri = URI.parse(path)
      begin
        case r = Net::HTTP.start(uri.host, uri.port) { |x| x.head(uri.path) }
        when Net::HTTPOK
          return r['Content-Length'.freeze].to_i
        else
          errors[path] = r
        end
      rescue => err
        errors[path] = err
      end
    end
    errors = errors.map { |path,err| "#{path} - #{err.message} (#{err.class})" }
    raise MogileFS::Error, "all paths failed with HEAD: #{errors.join(', ')}"
  end
end

git clone https://yhbt.net/mogilefs-client.git