| 279 | }; |
| 280 | |
| 281 | void TFsPath::ListNames(TVector<TString>& children) const { |
| 282 | CheckDefined(); |
| 283 | THolder<DIR, TClosedir> dir(opendir(this->c_str())); |
| 284 | if (!dir) { |
| 285 | ythrow TIoSystemError() << "failed to opendir " << Path_; |
| 286 | } |
| 287 | |
| 288 | for (;;) { |
| 289 | struct dirent de; |
| 290 | struct dirent* ok; |
| 291 | // TODO(yazevnul|IGNIETFERRO-1070): remove these macroses by replacing `readdir_r` with proper |
| 292 | // alternative |
| 293 | Y_PRAGMA_DIAGNOSTIC_PUSH |
| 294 | Y_PRAGMA_NO_DEPRECATED |
| 295 | int r = readdir_r(dir.Get(), &de, &ok); |
| 296 | Y_PRAGMA_DIAGNOSTIC_POP |
| 297 | if (r != 0) { |
| 298 | ythrow TIoSystemError() << "failed to readdir " << Path_; |
| 299 | } |
| 300 | if (ok == nullptr) { |
| 301 | return; |
| 302 | } |
| 303 | TString name(de.d_name); |
| 304 | if (name == "." || name == "..") { |
| 305 | continue; |
| 306 | } |
| 307 | children.push_back(name); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | bool TFsPath::Contains(const TString& component) const { |
| 312 | if (!IsDefined()) { |