zeroshade commented on code in PR #3099:
URL: https://github.com/apache/arrow-adbc/pull/3099#discussion_r2195944656


##########
rust/core/src/driver_manager.rs:
##########
@@ -161,8 +170,94 @@ struct ManagedDriverInner {
     _library: Option<libloading::Library>,
 }
 
+#[derive(Default)]
+struct DriverInfo {
+    manifest_file: std::path::PathBuf,
+    lib_path: std::path::PathBuf,
+    entrypoint: Option<Vec<u8>>,
+    // TODO: until we add more logging these are unused so we'll leave
+    // them out until such time that we do so.
+    // driver_name: String,
+    // version: String,
+    // source: String,
+}
+
+impl DriverInfo {
+    fn load_driver_manifest(&self) -> Result<Self> {
+        let contents = 
fs::read_to_string(self.manifest_file.as_path()).map_err(|e| {
+            Error::with_message_and_status(
+                format!(
+                    "Could not read manifest '{}': {e}",
+                    self.manifest_file.display()
+                ),
+                Status::InvalidArguments,
+            )
+        })?;
+
+        let manifest = contents
+            .parse::<Table>()
+            .map_err(|e| Error::with_message_and_status(e.to_string(), 
Status::InvalidArguments))?;
+
+        // leave these out until we add logging that would actually utilize 
them
+        // let driver_name = get_optional_key(&manifest, "name");
+        // let version = get_optional_key(&manifest, "version");
+        // let source = get_optional_key(&manifest, "source");
+        let (os, arch, extra) = arch_triplet();
+
+        let mut lib_path = PathBuf::default();
+        if let Some(driver) = manifest.get("Driver").and_then(|v| 
v.get("shared")) {
+            if driver.is_str() {
+                lib_path = PathBuf::from(driver.as_str().unwrap_or_default());
+            } else if driver.is_table() {
+                lib_path = PathBuf::from(
+                    driver
+                        .get(format!("{os}_{arch}{extra}"))
+                        .and_then(Value::as_str)
+                        .unwrap_or_default(),
+                );
+            }
+        }
+
+        if lib_path.as_os_str().is_empty() {
+            return Err(Error::with_message_and_status(
+                format!(
+                    "Manifest '{}' missing Driver.shared key of 
{os}_{arch}{extra}",

Review Comment:
   What's the benefit here of doing the match of `Some` and `None` there? It 
seems like it only complicates the code or introduces duplication rather than 
making it simpler. If the key exists but the value is an empty string, we want 
this error to happen still. I'm probably missing what you're suggesting, can 
you clarify?



-- 
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: github-unsubscr...@arrow.apache.org

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

Reply via email to