Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
import: Don't crash if we already have the object
Browse files Browse the repository at this point in the history
In this case ostree will just drop the reader, which
will break the pipe.

TODO: push rather than pull based file write API
  • Loading branch information
cgwalters committed Apr 6, 2021
1 parent 8bb07ac commit b924092
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/src/tar/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::variant_utils::variant_new_from_bytes;
use crate::Result;
use anyhow::anyhow;
use anyhow::{anyhow, Context};
use camino::Utf8Path;
use fn_error_context::context;
use std::collections::HashMap;
Expand Down Expand Up @@ -170,6 +170,12 @@ impl<'a> Importer<'a> {
xattrs: Option<&glib::Variant>,
) -> Result<()> {
let cancellable = gio::NONE_CANCELLABLE;
if self
.repo
.has_object(ostree::ObjectType::File, checksum, cancellable)?
{
return Ok(());
}
let (recv, mut send) = os_pipe::pipe()?;
let size = entry.header().size()?;
let header_copy = entry.header().clone();
Expand All @@ -183,7 +189,7 @@ impl<'a> Importer<'a> {
repo_clone.write_content(Some(checksum), &ostream, size, cancellable)?;
Ok(())
});
let n = std::io::copy(&mut entry, &mut send)?;
let n = std::io::copy(&mut entry, &mut send).context("Copying object content")?;
drop(send);
assert_eq!(n, size);
j.join().unwrap()?;
Expand All @@ -196,7 +202,7 @@ impl<'a> Importer<'a> {

/// Given a tar entry that looks like an object (its path is under ostree/repo/objects/),
/// determine its type and import it.
#[context("Importing object {}", path)]
#[context("object {}", path)]
fn import_object<'b, R: std::io::Read>(
&mut self,
entry: tar::Entry<'b, R>,
Expand Down

0 comments on commit b924092

Please sign in to comment.