flaneur2020 commented on code in PR #6283:
URL: https://github.com/apache/opendal/pull/6283#discussion_r2280229871


##########
integrations/object_store/src/service/mod.rs:
##########
@@ -0,0 +1,380 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::fmt::Debug;
+use std::fmt::Formatter;
+use std::sync::Arc;
+
+use object_store::ObjectStore;
+use opendal::raw::oio::BatchDeleter;
+use opendal::raw::oio::MultipartWriter;
+use opendal::raw::*;
+use opendal::Error;
+use opendal::ErrorKind;
+use opendal::*;
+
+mod deleter;
+mod error;
+mod lister;
+mod reader;
+mod writer;
+
+use deleter::ObjectStoreDeleter;
+use error::parse_error;
+use lister::ObjectStoreLister;
+use reader::ObjectStoreReader;
+use writer::ObjectStoreWriter;
+
+use crate::utils::format_metadata;
+
+/// ObjectStore backend builder
+#[derive(Default)]
+pub struct ObjectStoreBuilder {
+    store: Option<Arc<dyn ObjectStore + 'static>>,
+}
+
+impl Debug for ObjectStoreBuilder {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        let mut d = f.debug_struct("ObjectStoreBuilder");
+        d.finish_non_exhaustive()
+    }
+}
+
+impl ObjectStoreBuilder {
+    /// Set the object store instance
+    pub fn new(store: Arc<dyn ObjectStore + 'static>) -> Self {
+        Self { store: Some(store) }
+    }
+}
+
+impl Builder for ObjectStoreBuilder {
+    type Config = ();
+
+    fn build(self) -> Result<impl Access> {
+        let store = self.store.ok_or_else(|| {
+            Error::new(ErrorKind::ConfigInvalid, "object store is required")
+                .with_context("service", Scheme::Custom("object_store"))
+        })?;
+
+        Ok(ObjectStoreService { store })
+    }
+}
+
+/// ObjectStore backend
+pub struct ObjectStoreService {
+    store: Arc<dyn ObjectStore + 'static>,
+}
+
+impl Debug for ObjectStoreService {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        let mut d = f.debug_struct("ObjectStoreBackend");
+        d.finish_non_exhaustive()
+    }
+}
+
+impl Access for ObjectStoreService {
+    type Reader = ObjectStoreReader;
+    type Writer = MultipartWriter<ObjectStoreWriter>;
+    type Lister = ObjectStoreLister;
+    type Deleter = BatchDeleter<ObjectStoreDeleter>;
+
+    fn info(&self) -> Arc<AccessorInfo> {
+        let info = AccessorInfo::default();
+        info.set_scheme("object_store")
+            .set_root("/")
+            .set_name("object_store")
+            .set_native_capability(Capability {
+                stat: true,
+                stat_with_if_match: true,
+                stat_with_if_unmodified_since: true,
+                read: true,
+                write: true,
+                delete: true,
+                list: true,
+                list_with_limit: true,
+                list_with_start_after: true,
+                delete_with_version: false,
+                ..Default::default()
+            });
+        Arc::new(info)
+    }
+
+    async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
+        let path = object_store::path::Path::from(path);
+        let meta = self.store.head(&path).await.map_err(parse_error)?;

Review Comment:
   i was confused that `head()` does not have a `head_opts` counterparty which 
accepts options, i just found that `head()` is simply a wrapper over 
`get_opts()`. fixed it in 9299efcc93



-- 
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: commits-unsubscr...@opendal.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to