Google-cloud-ruby: Using "delimiter" parameter returns no results

Created on 21 Nov 2018  路  5Comments  路  Source: googleapis/google-cloud-ruby

Environment details

  • OS: macOS 10.13.6
  • Ruby version: 2.4.5
  • Gem name and version: google-cloud-storage (1.15.0)

Steps to reproduce

  1. Do not have list access (see: https://github.com/googleapis/google-cloud-ruby/issues/1590)
    > NOTE: I do not know if this is a factor in what I am seeing
  2. Attempt to use delimiter in #files
  3. See no results

Code example

irb> storage = Google::Cloud::Storage.new project_id: 'project'
irb> bucket  = storage.bucket 'bucket', skip_lookup: true

# Using prefix works
irb> bucket.files(prefix: "bucket/foo").collect { |f| f.name }
/bucket/foo/bar.png
/bucket/foo/test

# Adding a delimiter returns no results
irb> bucket.files(prefix: "bucket/foo", delimiter: "/").collect { |f| f.name }
(no results)
irb> bucket.files(delimiter: "/").collect { |f| f.name }
(no results
storage p2 bug

All 5 comments

I reproduced this without Step 1 (access) as follows:

irb(main):008:0> bucket = storage.create_bucket "files_delim"
=> #<Google::Cloud::Storage::Bucket:0x00007fe5eae81e80 ...
irb(main):010:0> bucket.create_file "test/google/cloud/storage/bucket_acl_test.rb", "test/google/cloud/storage/bucket_acl_test.rb"
=> #<Google::Cloud::Storage::File:0x00007fe5e94cdb88...
irb(main):011:0> bucket.create_file "test/google/cloud/storage/bucket_compose_test.rb", "test/google/cloud/storage/bucket_compose_test.rb"
=> #<Google::Cloud::Storage::File:0x00007fe5e943e2f8 ...
irb(main):014:0> bucket.files(prefix: "test/google/cloud/storage").collect { |f| f.name }
=> ["test/google/cloud/storage/bucket_acl_test.rb", "test/google/cloud/storage/bucket_compose_test.rb"]
irb(main):015:0> bucket.files(prefix: "test/google/cloud/storage", delimiter: "/").collect { |f| f.name }
=> []

Investigating now whether the cause might be in google-cloud-storage, or if these parameters are simply passed through to the Storage API service.

@eskerber Can you please try adding a trailing slash (/) to your prefix string? I think the problem is that because your prefix ends with foo (without a trailing slash), the resulting substrings for the "files" in the "foo directory" all begin with a slash. And the service API docs for delimiter state:

items will contain only objects whose names, aside from the prefix, do not contain delimiter.

I tested this myself with the following results:

irb(main):003:0>  bucket.files.collect { |f| f.name }
=> ["test/google/cloud/storage/bucket_acl_test.rb", "test/google/cloud/storage/bucket_compose_test.rb"]
irb(main):007:0>  bucket.files(prefix: "test/google/cloud/storage", delimiter: "/").collect { |f| f.name }
=> []
irb(main):008:0>  bucket.files(prefix: "test/google/cloud/storage/", delimiter: "/").collect { |f| f.name }
=> ["test/google/cloud/storage/bucket_acl_test.rb", "test/google/cloud/storage/bucket_compose_test.rb"]

Ping @eskerber

Making a note to test this tomorrow (or Weds). Thanks for following up!

Apologies - just caught me at the end of a paternity leave and need to dust off the old computer 馃榿

Gosh dang that was it - thanks for the tip!

Was this page helpful?
0 / 5 - 0 ratings