1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 15:45:53 +01:00

lib: Update to openat-ext 0.2.0

This commit is contained in:
Colin Walters
2021-04-06 15:35:02 +00:00
parent 0aa2d46fec
commit c0ce36c812
2 changed files with 4 additions and 18 deletions

View File

@@ -19,7 +19,7 @@ gvariant = "0.4.0"
hex = "0.4.3"
libc = "0.2.92"
openat = "0.1.20"
openat-ext = "0.1.13"
openat-ext = "0.2.0"
openssl = "0.10.33"
ostree = { version = "0.10.0", features = ["v2021_1" ]}
os_pipe = "0.9.2"

View File

@@ -22,8 +22,6 @@ const OCI_TYPE_LAYER: &str = "application/vnd.oci.image.layer.v1.tar+gzip";
pub(crate) const DOCKER_TYPE_LAYER: &str = "application/vnd.docker.image.rootfs.diff.tar.gzip";
// FIXME get rid of this after updating to https://github.com/coreos/openat-ext/pull/27
const TMPBLOB: &str = ".tmpblob";
/// Path inside an OCI directory to the blobs
const BLOBDIR: &str = "blobs/sha256";
@@ -96,7 +94,6 @@ pub(crate) struct Layer {
/// Create an OCI blob.
pub(crate) struct BlobWriter<'a> {
ocidir: &'a openat::Dir,
pub(crate) hash: Hasher,
pub(crate) target: Option<FileWriter<'a>>,
size: u64,
@@ -204,33 +201,22 @@ impl<'a> OciWriter<'a> {
}
}
impl<'a> Drop for BlobWriter<'a> {
fn drop(&mut self) {
if let Some(t) = self.target.take() {
// Defuse
let _ = t.abandon();
}
}
}
impl<'a> BlobWriter<'a> {
#[context("Creating blob writer")]
pub(crate) fn new(ocidir: &'a openat::Dir) -> Result<Self> {
Ok(Self {
ocidir,
hash: Hasher::new(MessageDigest::sha256())?,
// FIXME add ability to choose filename after completion
target: Some(ocidir.new_file_writer(TMPBLOB, 0o644)?),
target: Some(ocidir.new_file_writer(0o644)?),
size: 0,
})
}
#[context("Completing blob")]
pub(crate) fn complete(mut self) -> Result<Blob> {
self.target.take().unwrap().complete()?;
let sha256 = hex::encode(self.hash.finish()?);
self.ocidir
.local_rename(TMPBLOB, &format!("{}/{}", BLOBDIR, sha256))?;
let target = &format!("{}/{}", BLOBDIR, sha256);
self.target.take().unwrap().complete(target)?;
Ok(Blob {
sha256,
size: self.size,