| 3146 | std::string S3FileSystem::region() const { return impl_->region(); } |
| 3147 | |
| 3148 | Result<FileInfo> S3FileSystem::GetFileInfo(const std::string& s) { |
| 3149 | ARROW_ASSIGN_OR_RAISE(auto client_lock, impl_->holder_->Lock()); |
| 3150 | |
| 3151 | ARROW_ASSIGN_OR_RAISE(auto path, S3Path::FromString(s)); |
| 3152 | FileInfo info; |
| 3153 | info.set_path(s); |
| 3154 | |
| 3155 | if (path.empty()) { |
| 3156 | // It's the root path "" |
| 3157 | info.set_type(FileType::Directory); |
| 3158 | return info; |
| 3159 | } else if (path.key.empty()) { |
| 3160 | // It's a bucket |
| 3161 | S3Model::HeadBucketRequest req; |
| 3162 | req.SetBucket(ToAwsString(path.bucket)); |
| 3163 | |
| 3164 | auto outcome = client_lock.Move()->HeadBucket(req); |
| 3165 | if (!outcome.IsSuccess()) { |
| 3166 | impl_->GetOrSetBackend(outcome.GetError()); |
| 3167 | if (!IsNotFound(outcome.GetError())) { |
| 3168 | const auto msg = "When getting information for bucket '" + path.bucket + "': "; |
| 3169 | return ErrorToStatus(msg, "HeadBucket", outcome.GetError(), |
| 3170 | impl_->options().region); |
| 3171 | } |
| 3172 | info.set_type(FileType::NotFound); |
| 3173 | return info; |
| 3174 | } |
| 3175 | // NOTE: S3 doesn't have a bucket modification time. Only a creation |
| 3176 | // time is available, and you have to list all buckets to get it. |
| 3177 | info.set_type(FileType::Directory); |
| 3178 | return info; |
| 3179 | } else { |
| 3180 | // It's an object |
| 3181 | S3Model::HeadObjectRequest req; |
| 3182 | req.SetBucket(ToAwsString(path.bucket)); |
| 3183 | req.SetKey(ToAwsString(path.key)); |
| 3184 | |
| 3185 | auto outcome = client_lock.Move()->HeadObject(req); |
| 3186 | if (outcome.IsSuccess()) { |
| 3187 | // "File" object found |
| 3188 | FileObjectToInfo(path.key, outcome.GetResult(), &info); |
| 3189 | return info; |
| 3190 | } |
| 3191 | impl_->GetOrSetBackend(outcome.GetError()); |
| 3192 | if (!IsNotFound(outcome.GetError())) { |
| 3193 | const auto msg = "When getting information for key '" + path.key + "' in bucket '" + |
| 3194 | path.bucket + "': "; |
| 3195 | return ErrorToStatus(msg, "HeadObject", outcome.GetError(), |
| 3196 | impl_->options().region); |
| 3197 | } |
| 3198 | // Not found => perhaps it's an empty "directory" |
| 3199 | ARROW_ASSIGN_OR_RAISE(bool is_dir, impl_->IsEmptyDirectory(path, &outcome)); |
| 3200 | if (is_dir) { |
| 3201 | info.set_type(FileType::Directory); |
| 3202 | return info; |
| 3203 | } |
| 3204 | // Not found => perhaps it's a non-empty "directory" |
| 3205 | ARROW_ASSIGN_OR_RAISE(is_dir, impl_->IsNonEmptyDirectory(path)); |