From d341282ec24e4ed6080c18277bb6307f97f96a4f Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 31 Jan 2024 09:03:11 +0100 Subject: [PATCH] `source_by_zip_path` does not need to return an `Option` (#828) --- symbolic-debuginfo/src/sourcebundle.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/symbolic-debuginfo/src/sourcebundle.rs b/symbolic-debuginfo/src/sourcebundle.rs index c395f0d9..fbc8dc80 100644 --- a/symbolic-debuginfo/src/sourcebundle.rs +++ b/symbolic-debuginfo/src/sourcebundle.rs @@ -894,7 +894,7 @@ impl<'data> SourceBundleDebugSession<'data> { } /// Get source by the path of a file in the bundle. - fn source_by_zip_path(&self, zip_path: &str) -> Result, SourceBundleError> { + fn source_by_zip_path(&self, zip_path: &str) -> Result { let mut archive = self.archive.lock(); let mut file = archive .by_name(zip_path) @@ -903,7 +903,7 @@ impl<'data> SourceBundleDebugSession<'data> { file.read_to_string(&mut source_content) .map_err(|e| SourceBundleError::new(SourceBundleErrorKind::BadZip, e))?; - Ok(Some(source_content)) + Ok(source_content) } /// Looks up a source file descriptor. @@ -916,14 +916,16 @@ impl<'data> SourceBundleDebugSession<'data> { ) -> Result>, SourceBundleError> { if let Some(zip_path) = self.index.indexed_files.get(&key) { let zip_path = zip_path.as_str(); - let content = self.source_by_zip_path(zip_path)?; + let content = Cow::Owned(self.source_by_zip_path(zip_path)?); let info = self.index.manifest.files.get(zip_path); - return Ok(content.map(|opt| SourceFileDescriptor::new_embedded(Cow::Owned(opt), info))); + let descriptor = SourceFileDescriptor::new_embedded(content, info); + return Ok(Some(descriptor)); } let FileKey::Path(path) = key else { return Ok(None); }; + Ok(self .source_links .resolve(&path)