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

xuanwo pushed a commit to branch fix-stat
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/fix-stat by this push:
     new dcbfb7839 Fix swift
dcbfb7839 is described below

commit dcbfb78399cbe9dd962c8bf8ad74c630cea06d11
Author: Xuanwo <[email protected]>
AuthorDate: Thu Nov 23 14:54:22 2023 +0800

    Fix swift
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/src/services/swift/core.rs   | 8 +++-----
 core/src/services/swift/lister.rs | 5 ++---
 core/src/services/swift/writer.rs | 2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/src/services/swift/core.rs b/core/src/services/swift/core.rs
index 8fbbf9b43..e236339a2 100644
--- a/core/src/services/swift/core.rs
+++ b/core/src/services/swift/core.rs
@@ -17,8 +17,8 @@
 
 use std::fmt::Debug;
 
-use http::Request;
 use http::Response;
+use http::{header, Request};
 use serde::Deserialize;
 
 use crate::raw::*;
@@ -104,6 +104,7 @@ impl SwiftCore {
     pub async fn swift_create_object(
         &self,
         path: &str,
+        length: u64,
         body: AsyncBody,
     ) -> Result<Response<IncomingAsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -119,10 +120,7 @@ impl SwiftCore {
         let mut req = Request::put(&url);
 
         req = req.header("X-Auth-Token", &self.token);
-
-        if p.ends_with('/') {
-            req = req.header("Content-Length", "0");
-        }
+        req = req.header(header::CONTENT_LENGTH, length);
 
         let req = req.body(body).map_err(new_request_build_error)?;
 
diff --git a/core/src/services/swift/lister.rs 
b/core/src/services/swift/lister.rs
index 077fa3292..299326961 100644
--- a/core/src/services/swift/lister.rs
+++ b/core/src/services/swift/lister.rs
@@ -82,17 +82,16 @@ impl oio::PageList for SwiftLister {
                         continue;
                     }
 
-                    let mut meta = Metadata::new(EntryMode::FILE);
+                    let mut meta = Metadata::new(EntryMode::from_path(&name));
                     meta.set_content_length(bytes);
                     meta.set_content_md5(hash.as_str());
 
                     // we'll change "2023-10-28T19:18:11.682610" to 
"2023-10-28T19:18:11.682610Z"
                     last_modified.push('Z');
                     
meta.set_last_modified(parse_datetime_from_rfc3339(last_modified.as_str())?);
-
                     meta.set_content_type(content_type.as_str());
 
-                    oio::Entry::new(&name, meta)
+                    oio::Entry::with(name, meta)
                 }
             };
             ctx.entries.push_back(entry);
diff --git a/core/src/services/swift/writer.rs 
b/core/src/services/swift/writer.rs
index ca9cdbf35..eec46bc4a 100644
--- a/core/src/services/swift/writer.rs
+++ b/core/src/services/swift/writer.rs
@@ -44,7 +44,7 @@ impl oio::OneShotWrite for SwiftWriter {
 
         let resp = self
             .core
-            .swift_create_object(&self.path, AsyncBody::Bytes(bs))
+            .swift_create_object(&self.path, bs.len() as u64, 
AsyncBody::Bytes(bs))
             .await?;
 
         let status = resp.status();

Reply via email to