/usr/lib/ruby/vendor_ruby/fog/storage.rb is in ruby-fog-core 1.45.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | module Fog
module Storage
extend Fog::ServicesMixin
def self.new(orig_attributes)
begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
begin
require 'mime/types'
rescue LoadError
Fog::Logger.warning("'mime-types' missing, please install and try again.")
raise
end
end
attributes = orig_attributes.dup # prevent delete from having side effects
case attributes.delete(:provider).to_s.downcase.to_sym
when :internetarchive
require "fog/internet_archive/storage"
Fog::Storage::InternetArchive.new(attributes)
when :stormondemand
require "fog/storage/storm_on_demand"
Fog::Storage::StormOnDemand.new(attributes)
else
super(orig_attributes)
end
end
def self.directories
directories = []
providers.each do |provider|
begin
directories.concat(self[provider].directories)
rescue # ignore any missing credentials/etc
end
end
directories
end
def self.get_body_size(body)
if body.respond_to?(:encoding)
original_encoding = body.encoding
body = body.dup if body.frozen?
body = body.force_encoding('BINARY')
end
size = if body.respond_to?(:bytesize)
body.bytesize
elsif body.respond_to?(:size)
body.size
elsif body.respond_to?(:stat)
body.stat.size
else
0
end
if body.respond_to?(:encoding)
body.force_encoding(original_encoding)
end
size
end
def self.get_content_type(data)
if data.respond_to?(:path) && !data.path.nil?
filename = ::File.basename(data.path)
unless (mime_types = MIME::Types.of(filename)).empty?
mime_types.first.content_type
end
end
end
def self.parse_data(data)
{
:body => data,
:headers => {
"Content-Length" => get_body_size(data),
"Content-Type" => get_content_type(data)
# "Content-MD5" => Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
}
}
end
end
end
|