This is an automated email from the ASF dual-hosted git repository.

erose pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 1f57ff6ea7 HDDS-8437. [FSO] S3A compatibility - dfs -mkdir creates a 
zero byte file instead of a directory (#5124)
1f57ff6ea7 is described below

commit 1f57ff6ea7af532fdfe5fc8b1a11a5c53f744e43
Author: Mladjan Gadzic <[email protected]>
AuthorDate: Tue Sep 5 20:33:53 2023 +0200

    HDDS-8437. [FSO] S3A compatibility - dfs -mkdir creates a zero byte file 
instead of a directory (#5124)
---
 .../hadoop/ozone/s3/endpoint/ObjectEndpoint.java       | 18 ++++++++++++------
 .../java/org/apache/hadoop/ozone/s3/util/S3Consts.java |  3 +++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
index 62149a73d1..28c27977ac 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
@@ -81,6 +81,7 @@ import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
 import org.apache.hadoop.ozone.s3.util.RFC1123Util;
 import org.apache.hadoop.ozone.s3.util.RangeHeader;
 import org.apache.hadoop.ozone.s3.util.RangeHeaderParserUtil;
+import org.apache.hadoop.ozone.s3.util.S3Consts;
 import org.apache.hadoop.ozone.s3.util.S3StorageType;
 import org.apache.hadoop.ozone.s3.util.S3Utils;
 import org.apache.hadoop.ozone.web.utils.OzoneUtils;
@@ -241,13 +242,18 @@ public class ObjectEndpoint extends EndpointBase {
             "Connection", "close").build();
       }
 
-      if (length == 0 &&
-          ozoneConfiguration
-              .getBoolean(OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED,
-                  OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED_DEFAULT) &&
-          bucket.getBucketLayout() == BucketLayout.FILE_SYSTEM_OPTIMIZED) {
+      boolean canCreateDirectory = ozoneConfiguration
+          .getBoolean(OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED,
+              OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED_DEFAULT) &&
+          bucket.getBucketLayout() == BucketLayout.FILE_SYSTEM_OPTIMIZED;
+
+      String amzDecodedLength =
+          headers.getHeaderString(S3Consts.DECODED_CONTENT_LENGTH_HEADER);
+      boolean hasAmzDecodedLengthZero = amzDecodedLength != null &&
+          Long.parseLong(amzDecodedLength) == 0;
+      if (canCreateDirectory &&
+          (length == 0 || hasAmzDecodedLengthZero)) {
         s3GAction = S3GAction.CREATE_DIRECTORY;
-        // create directory
         getClientProtocol()
             .createDirectory(volume.getName(), bucketName, keyPath);
         return Response.ok().status(HttpStatus.SC_OK).build();
diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java
index f620fd624c..05e9503225 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java
@@ -64,4 +64,7 @@ public final class S3Consts {
 
   public static final String CUSTOM_METADATA_HEADER_PREFIX = "x-amz-meta-";
 
+  public static final String DECODED_CONTENT_LENGTH_HEADER =
+      "x-amz-decoded-content-length";
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to