Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sourcebundle): Added callback to skip over files #167

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions debuginfo/src/sourcebundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,14 +854,32 @@ where
/// sources could be resolved. Otherwise, an error is returned if writing the bundle fails.
///
/// This finishes the source bundle and flushes the underlying writer.
pub fn write_object<O>(
pub fn write_object<O>(self, object: &O, object_name: &str) -> Result<bool, SourceBundleError>
where
O: ObjectLike,
O::Error: Fail,
{
self.write_object_with_filter(object, object_name, |_| true)
}

/// Writes a single object into the bundle.
///
/// Returns `Ok(true)` if any source files were added to the bundle, or `Ok(false)` if no
/// sources could be resolved. Otherwise, an error is returned if writing the bundle fails.
///
/// This finishes the source bundle and flushes the underlying writer.
///
/// Before a file is written a callback is invoked which can return `false` to skip a file.
pub fn write_object_with_filter<O, F>(
mut self,
object: &O,
object_name: &str,
mut filter: F,
) -> Result<bool, SourceBundleError>
where
O: ObjectLike,
O::Error: Fail,
F: FnMut(&FileEntry) -> bool,
{
let mut files_handled = BTreeSet::new();
let session = object
Expand All @@ -883,7 +901,8 @@ where
continue;
}

let source = if filename.starts_with('<') && filename.ends_with('>') {
let source = if (filename.starts_with('<') && filename.ends_with('>')) || !filter(&file)
{
None
} else {
File::open(&filename).ok().map(BufReader::new)
Expand Down