lib/io_streams/paths/s3.rb in iostreams-1.0.0.beta6 vs lib/io_streams/paths/s3.rb in iostreams-1.0.0.beta7

- old
+ new

@@ -131,25 +131,25 @@ # @option params [String] :object_lock_legal_hold_status # The Legal Hold status that you want to apply to the specified object. def initialize(url, client: nil, access_key_id: nil, secret_access_key: nil, **args) Utils.load_soft_dependency('aws-sdk-s3', 'AWS S3') unless defined?(::Aws::S3::Client) - uri = URI.parse(url) + uri = Utils::URI.new(url) raise "Invalid URI. Required Format: 's3://<bucket_name>/<key>'" unless uri.scheme == 's3' - @bucket_name = uri.host + @bucket_name = uri.hostname key = uri.path.sub(%r{\A/}, '') if client.is_a?(Hash) client[:access_key_id] = access_key_id if access_key_id client[:secret_access_key] = secret_access_key if secret_access_key @client = ::Aws::S3::Client.new(client) else @client = client || ::Aws::S3::Client.new(access_key_id: access_key_id, secret_access_key: secret_access_key) end @options = args - URI.decode_www_form(uri.query).each { |key, value| @options[key] = value } if uri.query + @options.merge(uri.query) if uri.query super(key) end def to_s @@ -257,34 +257,39 @@ end # Notes: # - Currently all S3 lookups are recursive as of the pattern regardless of whether the pattern includes `**`. def each_child(pattern = "*", case_sensitive: false, directories: false, hidden: false) - raise(NotImplementedError, "AWS S3 #each_child does not yet return directories") if directories - matcher = Matcher.new(self, pattern, case_sensitive: case_sensitive, hidden: hidden) # When the pattern includes an exact file name without any pattern characters if matcher.pattern.nil? yield(matcher.path) if matcher.path.exist? return end - prefix = URI.parse(matcher.path.to_s).path.sub(%r{\A/}, '') + prefix = Utils::URI.new(matcher.path.to_s).path.sub(%r{\A/}, '') token = nil loop do # Fetches upto 1,000 entries at a time resp = client.list_objects_v2(bucket: bucket_name, prefix: prefix, continuation_token: token) resp.contents.each do |object| + next if !directories && object.key.end_with?("/") + file_name = ::File.join("s3://", resp.name, object.key) next unless matcher.match?(file_name) - yield self.class.new(file_name) + yield(self.class.new(file_name), object.to_h) end token = resp.next_continuation_token break if token.nil? end nil + end + + # On S3 only files that are completely saved are visible. + def partial_files_visible? + false end end end end