MCPcopy Create free account
hub / github.com/apache/arrow / GetFileInfo

Method GetFileInfo

cpp/src/arrow/filesystem/s3fs.cc:3148–3213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3146std::string S3FileSystem::region() const { return impl_->region(); }
3147
3148Result<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));

Callers 15

CreateDirMethod · 0.95
EnsureDestinationValidFunction · 0.45
TEST_FFunction · 0.45
TestGetFileInfoMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
GetAllWithTypeFunction · 0.45

Calls 15

ToAwsStringFunction · 0.85
IsNotFoundFunction · 0.85
ErrorToStatusFunction · 0.85
FileObjectToInfoFunction · 0.85
CollectAsyncGeneratorFunction · 0.85
GetOrSetBackendMethod · 0.80
IsNonEmptyDirectoryMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
emptyMethod · 0.45
MoveMethod · 0.45
optionsMethod · 0.45
GetResultMethod · 0.45

Tested by 15

TEST_FFunction · 0.36
TestGetFileInfoMethod · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
GetAllWithTypeFunction · 0.36
GetSortedInfosFunction · 0.36
TestGetFileInfoMethod · 0.36
TestGetFileInfoVectorMethod · 0.36
TESTFunction · 0.36