| 89 | } |
| 90 | |
| 91 | Status StatSelector(const std::string& wd, const std::string& path, |
| 92 | const FileSelector& select, int nesting_depth, |
| 93 | std::vector<FileInfo>* out) { |
| 94 | std::vector<io::HdfsPathInfo> children; |
| 95 | Status st = client_->ListDirectory(path, &children); |
| 96 | if (!st.ok()) { |
| 97 | if (select.allow_not_found) { |
| 98 | ARROW_ASSIGN_OR_RAISE(auto info, GetFileInfo(path)); |
| 99 | if (info.type() == FileType::NotFound) { |
| 100 | return Status::OK(); |
| 101 | } |
| 102 | } |
| 103 | return st; |
| 104 | } |
| 105 | for (const auto& child_path_info : children) { |
| 106 | // HDFS returns an absolute "URI" here, need to extract path relative to wd |
| 107 | // XXX: unfortunately, this is not a real URI as special characters |
| 108 | // are not %-escaped... hence parsing it as URI would fail. |
| 109 | std::string child_path; |
| 110 | if (!wd.empty()) { |
| 111 | if (child_path_info.name.substr(0, wd.length()) != wd) { |
| 112 | return Status::IOError("HDFS returned path '", child_path_info.name, |
| 113 | "' that is not a child of '", wd, "'"); |
| 114 | } |
| 115 | child_path = child_path_info.name.substr(wd.length()); |
| 116 | } else { |
| 117 | child_path = child_path_info.name; |
| 118 | } |
| 119 | |
| 120 | FileInfo info; |
| 121 | info.set_path(child_path); |
| 122 | PathInfoToFileInfo(child_path_info, &info); |
| 123 | const bool is_dir = info.type() == FileType::Directory; |
| 124 | out->push_back(std::move(info)); |
| 125 | if (is_dir && select.recursive && nesting_depth < select.max_recursion) { |
| 126 | RETURN_NOT_OK(StatSelector(wd, child_path, select, nesting_depth + 1, out)); |
| 127 | } |
| 128 | } |
| 129 | return Status::OK(); |
| 130 | } |
| 131 | |
| 132 | Result<std::vector<FileInfo>> GetFileInfo(const FileSelector& select) { |
| 133 | // See GetFileInfo(const std::string&) above. |
nothing calls this directly
no test coverage detected