westonpace commented on code in PR #35440:
URL: https://github.com/apache/arrow/pull/35440#discussion_r1243017032


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -2344,42 +2352,28 @@ FileInfoGenerator 
S3FileSystem::GetFileInfoGenerator(const FileSelector& select)
   }
   auto base_path = *std::move(maybe_base_path);
 
-  if (base_path.empty()) {
-    // List all buckets, then possibly recurse
-    PushGenerator<AsyncGenerator<FileInfoVector>> gen;
-    auto producer = gen.producer();
-
-    auto fut = impl_->ListBucketsAsync(io_context());
-    auto impl = impl_->shared_from_this();
-    fut.AddCallback(
-        [producer, select, impl](const Result<std::vector<std::string>>& res) 
mutable {
-          if (!res.ok()) {
-            producer.Push(res.status());
-            producer.Close();
-            return;
-          }
-          FileInfoVector buckets;
-          for (const auto& bucket : *res) {
-            buckets.push_back(FileInfo{bucket, FileType::Directory});
-          }
-          // Generate all bucket infos
-          auto buckets_fut = 
Future<FileInfoVector>::MakeFinished(std::move(buckets));
-          producer.Push(MakeSingleFutureGenerator(buckets_fut));
-          if (select.recursive) {
-            // Generate recursive walk for each bucket in turn
-            for (const auto& bucket : *buckets_fut.result()) {
-              producer.Push(impl->WalkAsync(select, bucket.path(), ""));
-            }
-          }
-          producer.Close();
-        });
+  PushGenerator<std::vector<FileInfo>> generator;
+  auto start_listing = [&, sink = generator.producer()](
+                           util::AsyncTaskScheduler* scheduler) {
+    if (base_path.empty()) {
+      bool should_recurse = select.recursive && select.max_recursion > 0;
+      impl_->FullListAsync(/*include_virtual=*/true, scheduler, sink, 
io_context(),
+                           should_recurse);
+    } else {
+      impl_->ListAsync(select, base_path.bucket, base_path.key,
+                       /*include_virtual=*/true, scheduler, sink, 
/*close_sink=*/false);
+    }
+    return Status::OK();
+  };
 
-    return MakeConcatenatedGenerator(
-        AsyncGenerator<AsyncGenerator<FileInfoVector>>{std::move(gen)});
-  }
+  Future<> all_done_fut = util::AsyncTaskScheduler::Make(
+      std::move(start_listing), [](const Status&) {}, 
StopToken::Unstoppable());

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to