apache / apache/arrow-rs-object-store
Improve handling of directories in `ObjectStore::list`
- Dominant language
- Rust
- Stars
- 322
- Forks
- 212
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 10
Description
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
I am trying to use the least boilerplate code to copy a subdir from a bucket on GCP preserving the "directory" structure.
Meaning treating `/` as a directory locally.
The `TryFrom for ObjectMeta` strips trailing `/` from the path making it impossible to identify whether an ObjectMeta is a directory or not. This requires an extra call to check if the file exists.
Looking at other s3 clients that implement a list operation, e.g. https://github.com/rclone/rclone/blob/master/backend/s3/s3.go#L4753, we can see that rclone interprets a trailing `/` with size == 0 as a directory marker.
**Describe the solution you'd like**
It would be nice if ObjectMeta would provide an `is_directory` flag (or Option for backends that don't emit such "virtual" files) or similar.
There is https://github.com/apache/arrow-rs-object-store/issues/284 without any outcome yet.
**Describe alternatives you've considered**
We could use a concrete `[GoogleCloudStorage](https://docs.rs/object_store/latest/object_store/gcp/struct.GoogleCloudStorage.html)` to use `PaginatedListStore::list_paginated` (which avoids the conversion into `ObjectMeta` which would preserve the trailing `/`.
But we would like to keep supporting `parse_url` and different backends, and there is no way to downcast to a concrete store right now.
https://github.com/apache/arrow-rs/issues/7026#issuecomment-2615184698 talks about just filtering them out instead of exposing them to the caller.
I am not sure which solution is best. I think exposing an `is_directory` to the caller is better because I think a file ending in `/` even with size 0, would be a valid file, at least in Google Cloud Storage. But at least the Web Console and the gcloud CLI don't let you create such a file.
**Additional context**
Google Cloud Storage or rather some clients, actually create zero sized objects for folders, which you can download. But due to the stripping, the Path is invalid. Also, it doesn't make much sense to download these zero-sized objects, as they would prevent the creation of a directory locally.
Contributor guide
Research direction
Start at ObjectStore::list and the TryFrom for ObjectMeta conversion, then compare them with PaginatedListStore::list_paginated and GoogleCloudStorage behavior. Decide how directory markers and trailing slashes should be represented across backends, and verify that callers can preserve directory structure without an extra existence check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, rust
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100