felipecrv commented on code in PR #38845:
URL: https://github.com/apache/arrow/pull/38845#discussion_r1402702389


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -2408,7 +2408,11 @@ class S3FileSystem::Impl : public 
std::enable_shared_from_this<S3FileSystem::Imp
                   std::vector<std::string> file_paths;
                   for (const auto& file_info : file_infos) {
                     DCHECK_GT(file_info.path().size(), bucket.size());
-                    file_paths.push_back(file_info.path().substr(bucket.size() 
+ 1));
+                    auto file_path = file_info.path().substr(bucket.size() + 
1);
+                    if (file_info.IsDirectory()) {
+                      file_path = file_path + kSep;

Review Comment:
   Can you `DCHECK` here that `file_path` doesn't end with a `/` (kSep)?
   
   It looks like `FileInfo` is normalizing paths to never end with `/` and this 
`DCHECK` can protect us if that changes in the future.



##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -2408,7 +2408,11 @@ class S3FileSystem::Impl : public 
std::enable_shared_from_this<S3FileSystem::Imp
                   std::vector<std::string> file_paths;
                   for (const auto& file_info : file_infos) {
                     DCHECK_GT(file_info.path().size(), bucket.size());
-                    file_paths.push_back(file_info.path().substr(bucket.size() 
+ 1));
+                    auto file_path = file_info.path().substr(bucket.size() + 
1);
+                    if (file_info.IsDirectory()) {
+                      file_path = file_path + kSep;
+                    }
+                    file_paths.push_back(file_path);

Review Comment:
   Now that `file_path` lives in a variable, you need to explicitly `std::move` 
it to avoid a copy when pushing:
   
   ```cpp
   file_paths.push_back(std::move(file_path));
   ```



-- 
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