| 386 | } |
| 387 | |
| 388 | Status HadoopFileSystem::GetChildren(const string& dir, |
| 389 | std::vector<string>* result) { |
| 390 | result->clear(); |
| 391 | hdfsFS fs = nullptr; |
| 392 | TF_RETURN_IF_ERROR(Connect(dir, &fs)); |
| 393 | |
| 394 | // hdfsListDirectory returns nullptr if the directory is empty. Do a separate |
| 395 | // check to verify the directory exists first. |
| 396 | FileStatistics stat; |
| 397 | TF_RETURN_IF_ERROR(Stat(dir, &stat)); |
| 398 | |
| 399 | int entries = 0; |
| 400 | hdfsFileInfo* info = |
| 401 | hdfs_->hdfsListDirectory(fs, TranslateName(dir).c_str(), &entries); |
| 402 | if (info == nullptr) { |
| 403 | if (stat.is_directory) { |
| 404 | // Assume it's an empty directory. |
| 405 | return Status::OK(); |
| 406 | } |
| 407 | return IOError(dir, errno); |
| 408 | } |
| 409 | for (int i = 0; i < entries; i++) { |
| 410 | result->push_back(string(io::Basename(info[i].mName))); |
| 411 | } |
| 412 | hdfs_->hdfsFreeFileInfo(info, entries); |
| 413 | return Status::OK(); |
| 414 | } |
| 415 | |
| 416 | Status HadoopFileSystem::GetMatchingPaths(const string& pattern, |
| 417 | std::vector<string>* results) { |