delimiter in #filesirb> 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
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!