pitrou commented on code in PR #41822:
URL: https://github.com/apache/arrow/pull/41822#discussion_r1625943313


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -2859,17 +2859,41 @@ Status S3FileSystem::CreateDir(const std::string& s, 
bool recursive) {
     return impl_->CreateBucket(path.bucket);
   }
 
+  FileInfo file_info;
   // Create object
   if (recursive) {
     // Ensure bucket exists
     ARROW_ASSIGN_OR_RAISE(bool bucket_exists, 
impl_->BucketExists(path.bucket));
     if (!bucket_exists) {
       RETURN_NOT_OK(impl_->CreateBucket(path.bucket));
     }
+
+    auto key_i = path.key_parts.begin();
+    std::string parent_key{};
+    if (options().check_directory_existence_before_creation) {
+      // Walk up the directory first to find the first existing parent
+      for (const auto& part : path.key_parts) {
+        parent_key += part;
+        parent_key += kSep;
+      }
+      for (key_i = path.key_parts.end(); key_i-- != path.key_parts.begin();) {
+        ARROW_ASSIGN_OR_RAISE(file_info,
+                              this->GetFileInfo(path.bucket + kSep + 
parent_key));
+        if (file_info.type() != FileType::NotFound) {
+          /// Found!

Review Comment:
   We should keep triple-slashes (`///`) for docstrings and use double-slashes 
(`//`) for comments.
   ```suggestion
             // Found!
   ```



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