You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/11/14 09:39:18 UTC

(opendal) 06/06: Add cos

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

xuanwo pushed a commit to branch add-write-if-not-exists
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 036ead049e0ae724f0ee0ad1ddccc4c6891fff07
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Thu Nov 14 17:38:41 2024 +0800

    Add cos
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/services/cos/backend.rs |  2 ++
 core/src/services/cos/core.rs    | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs
index 6065dca95..df297d196 100644
--- a/core/src/services/cos/backend.rs
+++ b/core/src/services/cos/backend.rs
@@ -258,6 +258,8 @@ impl Access for CosBackend {
                 write_with_content_type: true,
                 write_with_cache_control: true,
                 write_with_content_disposition: true,
+                // TODO: set this to false while version has been enabled.
+                write_with_if_not_exists: true,
                 // The min multipart size of COS is 1 MiB.
                 //
                 // ref: <https://www.tencentcloud.com/document/product/436/14112>
diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs
index f7dbdef60..4d28b2688 100644
--- a/core/src/services/cos/core.rs
+++ b/core/src/services/cos/core.rs
@@ -172,6 +172,18 @@ impl CosCore {
             req = req.header(CONTENT_TYPE, mime)
         }
 
+        // For a bucket which has never enabled versioning, you may use it to
+        // specify whether to prohibit overwriting the object with the same name
+        // when uploading the object:
+        //
+        // When the x-cos-forbid-overwrite is specified as true, overwriting the object
+        // with the same name will be prohibited.
+        //
+        // ref: https://www.tencentcloud.com/document/product/436/7749
+        if args.if_not_exists() {
+            req = req.header("x-cos-forbid-overwrite", "true")
+        }
+
         let req = req.body(body).map_err(new_request_build_error)?;
 
         Ok(req)