Skip to content

Commit

Permalink
feat(sourcebundle): Added callback to skip over files (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Nov 18, 2019
1 parent 05631ed commit e7c8ff5
Showing 1 changed file with 21 additions and 2 deletions.
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

0 comments on commit e7c8ff5

Please sign in to comment.