Skip to content

Commit 9e55fec

Browse files
vaindloewenheim
andauthored
feat: change SourceBundleWriter::write_object_with_filter() filter callback to take SourceCode (#764)
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
1 parent 6394b02 commit 9e55fec

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Breaking changes**:
66

77
- Change `DebugSession::source_by_path()` to return `SourceCode` enum with either file content or a URL to fetch it from. ([#758](https://github.com/getsentry/symbolic/pull/758))
8+
- Change `SourceBundleWriter::write_object_with_filter()` filter callback to take `SourceCode`, allowing to include/exclude embedded sources. ([#764](https://github.com/getsentry/symbolic/pull/764))
89

910
**Fixes**:
1011

symbolic-debuginfo/src/sourcebundle.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ where
781781
}
782782

783783
/// This controls if source files should be scanned for Il2cpp-specific source annotations,
784-
/// and the referenced C# files should be bundled ups as well.
784+
/// and the referenced C# files should be bundled up as well.
785785
pub fn collect_il2cpp_sources(&mut self, collect_il2cpp: bool) {
786786
self.collect_il2cpp = collect_il2cpp;
787787
}
@@ -893,7 +893,7 @@ where
893893
O: ObjectLike<'data, 'object, Error = E>,
894894
E: std::error::Error + Send + Sync + 'static,
895895
{
896-
self.write_object_with_filter(object, object_name, |_| true)
896+
self.write_object_with_filter(object, object_name, |_, _| true)
897897
}
898898

899899
/// Writes a single object into the bundle.
@@ -913,7 +913,7 @@ where
913913
where
914914
O: ObjectLike<'data, 'object, Error = E>,
915915
E: std::error::Error + Send + Sync + 'static,
916-
F: FnMut(&FileEntry) -> bool,
916+
F: FnMut(&FileEntry, &Option<SourceCode<'_>>) -> bool,
917917
{
918918
let mut files_handled = BTreeSet::new();
919919
let mut referenced_files = BTreeSet::new();
@@ -938,11 +938,19 @@ where
938938
continue;
939939
}
940940

941-
let source = if (filename.starts_with('<') && filename.ends_with('>')) || !filter(&file)
942-
{
941+
let source = if filename.starts_with('<') && filename.ends_with('>') {
943942
None
944943
} else {
945-
std::fs::read(&filename).ok()
944+
let source_from_object = session
945+
.source_by_path(&filename)
946+
.map_err(|e| SourceBundleError::new(SourceBundleErrorKind::BadDebugFile, e))?;
947+
if filter(&file, &source_from_object) {
948+
// Note: we could also use source code directly from the object, but that's not
949+
// what happened here previously - only collected locally present files.
950+
std::fs::read(&filename).ok()
951+
} else {
952+
None
953+
}
946954
};
947955

948956
if let Some(source) = source {

0 commit comments

Comments
 (0)