Skip to content

Commit

Permalink
Fix bundle creation (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck authored Jun 12, 2023
1 parent ce74a74 commit 4cd9094
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Don't include any debug bundle generated during a run of Broker or FOSSA CLI.
fossa.broker.debug.tar.gz
fossa.debug.json.gz

# Node isn't used for this actual project, but we have a node test fixture
# to make tests run faster.
node_modules
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

## v0.2.2

Bug fix:

- Broker now copies its debug bundle (generated during `broker fix`) from the system temp location instead of renaming.
This resolves issues preventing debug bundles from being stored for Linux installations where the temporary location
and the home folder are on separate mount points.

## v0.2.1

Features:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "broker"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
description = "The bridge between FOSSA and internal DevOps services"
readme = "README.md"
Expand Down
12 changes: 10 additions & 2 deletions src/debug/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Trait and implementations used by `bundle` to create debug bundles.
use std::path::Path;
use std::{fs, path::Path};

use error_stack::Result;
use libflate::gzip;
Expand Down Expand Up @@ -50,6 +50,7 @@ impl TarGz {
///
/// This bundles the provided debug artifacts using a backing temp file,
/// which is moved to a final location with the `finalize` method.
#[tracing::instrument]
pub fn new() -> Result<Self, Error> {
let file = NamedTempFile::new().context(Error::CreateTempFile)?;
let encoder = gzip::Encoder::new(file).context(Error::CreateBundler)?;
Expand All @@ -62,6 +63,7 @@ impl TarGz {
impl Bundler for TarGz {
type Error = std::io::Error;

#[tracing::instrument(skip_all, fields(path = %path.as_ref().display(), name = %name.as_ref().display()))]
fn add_file<P, N>(&mut self, path: P, name: N) -> std::result::Result<(), Self::Error>
where
P: AsRef<Path>,
Expand All @@ -70,11 +72,17 @@ impl Bundler for TarGz {
self.inner.append_path_with_name(path, name)
}

#[tracing::instrument(skip_all, fields(destination = %destination.as_ref().display()))]
fn finalize<P: AsRef<Path>>(self, destination: P) -> std::result::Result<Bundle, Self::Error> {
let zip = self.inner.into_inner()?;
let handle = zip.finish().into_result()?;
handle.as_file().sync_all()?;
handle.persist(&destination)?;

// `handle.persist` fails if asked to persist across mounts, since internally it uses a rename.
// Instead, just copy the file from temp.
let path = handle.into_temp_path();
fs::copy(&path, destination.as_ref())?;

Ok(Bundle {
location: destination.as_ref().to_path_buf(),
})
Expand Down

0 comments on commit 4cd9094

Please sign in to comment.