Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Mar 7, 2022
1 parent 993418d commit 2e9ecbb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ sanitizers = []
default = []

[patch.crates-io]
ostree-ext = { git = "https://github.com/cgwalters/ostree-rs-ext", branch = "tar-split" }
#ostree-ext = { path = "../../ostreedev/ostree-rs-ext/lib" }
#ostree-ext = { git = "https://github.com/cgwalters/ostree-rs-ext", branch = "tar-split" }
ostree-ext = { path = "../../ostreedev/ostree-rs-ext/lib" }
2 changes: 1 addition & 1 deletion rust/src/composepost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) static COMPAT_VARLIB_SYMLINKS: &[&str] = &["alternatives", "vagrant"]

/* See rpmostree-core.h */
const RPMOSTREE_BASE_RPMDB: &str = "usr/lib/sysimage/rpm-ostree-base-db";
const RPMOSTREE_RPMDB_LOCATION: &str = "usr/share/rpm";
pub(crate) const RPMOSTREE_RPMDB_LOCATION: &str = "usr/share/rpm";
const RPMOSTREE_SYSIMAGE_RPMDB: &str = "usr/lib/sysimage/rpm";
pub(crate) const TRADITIONAL_RPMDB_LOCATION: &str = "var/lib/rpm";

Expand Down
36 changes: 31 additions & 5 deletions rust/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use std::rc::Rc;

use anyhow::Result;
use camino::{Utf8Path, Utf8PathBuf};
use cap_std::fs::Dir;
use cap_std_ext::cap_std;
use cap_std_ext::prelude::*;
use chrono::prelude::*;
use ostree::glib;
use ostree_ext::chunking::Chunking;
use ostree_ext::chunking::{Chunking, ObjectMetaSized};
use ostree_ext::objectsource::{
ContentID, ObjectMeta, ObjectMetaMap, ObjectMetaSet, ObjectSourceMeta,
};
Expand Down Expand Up @@ -38,6 +41,10 @@ struct ContentMappingOpts {

#[structopt(long = "ref")]
ostree_ref: String,

#[structopt(long)]
/// Output content metadata as JSON
write_contentmeta_json: Option<Utf8PathBuf>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -210,6 +217,7 @@ pub fn content_mapping(args: &[&str]) -> Result<()> {
state.packagemeta.insert(ObjectSourceMeta {
identifier: Rc::clone(&state.unpackaged_id),
name: Rc::clone(&state.unpackaged_id),
srcid: Rc::clone(&state.unpackaged_id),
// Assume that content in here changes frequently.
change_time_offset: u32::MAX,
});
Expand Down Expand Up @@ -254,6 +262,7 @@ pub fn content_mapping(args: &[&str]) -> Result<()> {
state.packagemeta.insert(ObjectSourceMeta {
identifier: Rc::clone(&nevra),
name: Rc::clone(&nevra),
srcid: Rc::from(pkgmeta.src_pkg().to_str().unwrap()),
change_time_offset,
});
}
Expand All @@ -271,21 +280,29 @@ pub fn content_mapping(args: &[&str]) -> Result<()> {
state.content.insert(checksum.to_string(), Rc::clone(&name));
state.packagemeta.insert(ObjectSourceMeta {
identifier: Rc::clone(&name),
name,
name: Rc::clone(&name),
srcid: Rc::clone(&name),
change_time_offset: u32::MAX,
});
state.skip.insert(path);
}
}

let rpmdb = root.resolve_relative_path(crate::composepost::RPMOSTREE_RPMDB_LOCATION);
if rpmdb.query_exists(gio::NONE_CANCELLABLE) {
// TODO add mapping for rpmdb
}

// Walk the filesystem
build_mapping_recurse(&mut Utf8PathBuf::from("/"), &root, &q, &mut state)?;
let src_pkgs: HashSet<_> = state.packagemeta.iter().map(|p| &p.srcid).collect();

// Print out information about what we found
println!(
"{} objects in {} packages",
"{} objects in {} packages ({} source)",
state.content.len(),
state.packagemeta.len()
state.packagemeta.len(),
src_pkgs.len(),
);
println!("rpm size: {}", state.rpmsize);
println!(
Expand All @@ -305,8 +322,17 @@ pub fn content_mapping(args: &[&str]) -> Result<()> {
// Convert our build state into the state that ostree consumes, discarding
// transient data such as the cases of files owned by multiple packages.
let meta: ObjectMeta = state.into();
// Now generate the sized version
let meta = ObjectMetaSized::compute_sizes(&repo, meta)?;
if let Some(v) = opt.write_contentmeta_json {
let v = v.strip_prefix("/").unwrap_or(&v);
let root = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
root.replace_file_with(v, |w| {
serde_json::to_writer(w, &meta.sizes).map_err(anyhow::Error::msg)
})?;
}
// Ask ostree to convert this data into chunks
let chunking = Chunking::from_mapping(&repo, rev.as_str(), &meta)?;
let chunking = Chunking::from_mapping(&repo, rev.as_str(), meta)?;

// Just print it for now.
chunking.print();
Expand Down
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ pub mod ffi {
// Methods on PackageMeta
fn size(self: &PackageMeta) -> u64;
fn buildtime(self: &PackageMeta) -> u64;
fn src_pkg(self: &PackageMeta) -> &CxxString;
}

// rpmostree-package-variants.h
Expand Down
3 changes: 3 additions & 0 deletions src/libpriv/rpmostree-refts.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "config.h"

#include <rpm/header.h>
#include <rpm/rpmtag.h>
#include <string.h>
#include "rpmostree-refts.h"
#include "rpmostree-rpm-util.h"
Expand Down Expand Up @@ -110,6 +112,7 @@ RpmTs::package_meta(const rust::Str name) const {
previous = util::move_nullify(nevra);
retval->_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
retval->_buildtime = headerGetNumber(h, RPMTAG_BUILDTIME);
retval->_src_pkg = headerGetString(h, RPMTAG_SOURCERPM);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/libpriv/rpmostree-refts.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ namespace rpmostreecxx {
struct PackageMeta {
uint64_t _size;
uint64_t _buildtime;
std::string _src_pkg;

uint64_t size() const { return _size; };
uint64_t buildtime() const { return _buildtime; };
const std::string& src_pkg() const { return _src_pkg; };
};

// A simple C++ wrapper for a librpm C type, so we can expose it to Rust via cxx.rs.
Expand Down

0 comments on commit 2e9ecbb

Please sign in to comment.