@@ -375,34 +375,35 @@ std::vector<directory_entry> Posix::ls_with_sizes(const URI& uri) const {
375375 if (!strcmp (next_path->d_name , " ." ) || !strcmp (next_path->d_name , " .." ))
376376 continue ;
377377 std::string abspath = path + " /" + next_path->d_name ;
378- // Do not attempt to retrieve file size for temporary metadata files that
379- // are still flushing to disk.
380- const bool temp_metadata =
381- URI (abspath)
382- .parent_path ()
383- .remove_trailing_slash ()
384- .to_string ()
385- .ends_with (constants::array_metadata_dir_name) &&
386- abspath.ends_with (constants::temp_file_suffix);
387-
388- // Getting the file size here incurs an additional system call
389- // via file_size() and ls() calls will feel this too.
390- // If this penalty becomes noticeable, we should just duplicate
391- // this implementation in ls() and don't get the size
378+
392379 if (next_path->d_type == DT_DIR) {
393380 entries.emplace_back (abspath, 0 , true );
394381 } else {
395- uint64_t size = temp_metadata ? 0 : file_size (URI (abspath));
396- entries.emplace_back (abspath, size, false );
382+ entries.emplace_back (abspath, file_size (URI (abspath)), false );
397383 }
398384 }
399385 return entries;
400386}
401387
402388Status Posix::ls (
403389 const std::string& path, std::vector<std::string>* paths) const {
404- for (auto & fs : ls_with_sizes (URI (path))) {
405- paths->emplace_back (fs.path ().native ());
390+ struct dirent * next_path = nullptr ;
391+ auto dir = PosixDIR::open (path);
392+ if (dir.empty ()) {
393+ return {};
394+ }
395+
396+ while ((next_path = readdir (dir.get ())) != nullptr ) {
397+ if (!strcmp (next_path->d_name , " ." ) || !strcmp (next_path->d_name , " .." )) {
398+ continue ;
399+ }
400+ std::string abspath = path + " /" + next_path->d_name ;
401+
402+ if (next_path->d_type == DT_DIR) {
403+ paths->emplace_back (abspath);
404+ } else {
405+ paths->emplace_back (abspath);
406+ }
406407 }
407408
408409 return Status::Ok ();
0 commit comments