Skip to content

Commit

Permalink
Add install --force-replacefiles
Browse files Browse the repository at this point in the history
Add support for RPMs which want to override files from other RPMs. This
could be useful generally, but specifically for example in OCP where
we're toying with bundling user-provided overrides as RPMs.

We're effectively surfacing rpm's `--replacefiles` switch, though in a
slightly safer way because while we do turn on the associated rpmdb flag
globally (`RPMPROB_FILTER_REPLACEOLDFILES`), we're only allowing the
checkouts of those specific packages to replace files.

This is also rendered separately in `status` as `LocalForcedPackages`.
  • Loading branch information
jlebon authored and cgwalters committed Oct 14, 2021
1 parent 77636fc commit 6783b0a
Show file tree
Hide file tree
Showing 22 changed files with 255 additions and 25 deletions.
5 changes: 5 additions & 0 deletions rust/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ fn deployment_populate_variant_origin(
"requested-local-packages",
tf.derive.packages_local.as_ref(),
);
vdict_insert_optmap(
dict,
"requested-local-fileoverride-packages",
tf.derive.packages_local_fileoverride.as_ref(),
);
vdict_insert_optvec(
dict,
"requested-base-removals",
Expand Down
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ pub mod ffi {
fn get_repos(&self) -> Vec<String>;
fn get_packages(&self) -> Vec<String>;
fn get_packages_local(&self) -> Vec<String>;
fn get_packages_local_fileoverride(&self) -> Vec<String>;
fn get_packages_override_replace_local(&self) -> Vec<String>;
fn get_packages_override_remove(&self) -> Vec<String>;
fn get_modules_enable(&self) -> Vec<String>;
Expand Down
10 changes: 9 additions & 1 deletion rust/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const OVERRIDES: &str = "overrides";
/// The set of keys that we parse as BTreeMap and need to ignore ordering changes.
static UNORDERED_LIST_KEYS: phf::Set<&'static str> = phf::phf_set! {
"packages/local",
"packages/local-fileoverride",
"overrides/replace-local"
};

Expand All @@ -45,6 +46,8 @@ pub(crate) fn origin_to_treefile_inner(kf: &KeyFile) -> Result<Box<Treefile>> {
cfg.derive.base_refspec = Some(refspec_str);
cfg.packages = parse_stringlist(kf, PACKAGES, "requested")?;
cfg.derive.packages_local = parse_localpkglist(kf, PACKAGES, "requested-local")?;
cfg.derive.packages_local_fileoverride =
parse_localpkglist(kf, PACKAGES, "requested-local-fileoverride")?;
let modules_enable = parse_stringlist(kf, MODULES, "enable")?;
let modules_install = parse_stringlist(kf, MODULES, "install")?;
if modules_enable.is_some() || modules_install.is_some() {
Expand Down Expand Up @@ -132,7 +135,9 @@ fn treefile_to_origin_inner(tf: &Treefile) -> Result<glib::KeyFile> {
let kf = glib::KeyFile::new();

// refspec (note special handling right now for layering)
let deriving = tf.packages.is_some() || tf.derive.packages_local.is_some();
let deriving = tf.packages.is_some()
|| tf.derive.packages_local.is_some()
|| tf.derive.packages_local_fileoverride.is_some();
if let Some(r) = tf.derive.base_refspec.as_deref() {
let k = if deriving { "baserefspec" } else { "refspec" };
kf.set_string(ORIGIN, k, r)
Expand All @@ -146,6 +151,9 @@ fn treefile_to_origin_inner(tf: &Treefile) -> Result<glib::KeyFile> {
if let Some(pkgs) = tf.derive.packages_local.as_ref() {
set_sha256_nevra_pkgs(&kf, PACKAGES, "requested-local", pkgs)
}
if let Some(pkgs) = tf.derive.packages_local_fileoverride.as_ref() {
set_sha256_nevra_pkgs(&kf, PACKAGES, "requested-local-fileoverride", pkgs)
}
if let Some(pkgs) = tf.derive.override_remove.as_deref() {
let pkgs = pkgs.iter().map(|s| s.as_str());
kf_set_string_list(&kf, OVERRIDES, "remove", pkgs)
Expand Down
13 changes: 13 additions & 0 deletions rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ impl Treefile {
.collect()
}

pub(crate) fn get_packages_local_fileoverride(&self) -> Vec<String> {
self.parsed
.derive
.packages_local_fileoverride
.iter()
.flatten()
.map(|(k, v)| format!("{}:{}", v, k))
.collect()
}

pub(crate) fn get_modules_enable(&self) -> Vec<String> {
self.parsed
.modules
Expand Down Expand Up @@ -1339,6 +1349,8 @@ pub(crate) struct DeriveConfigFields {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) packages_local: Option<BTreeMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) packages_local_fileoverride: Option<BTreeMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) override_remove: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) override_replace_local: Option<BTreeMap<String, String>>,
Expand Down Expand Up @@ -1369,6 +1381,7 @@ impl DeriveConfigFields {
}
check!(base_refspec);
check!(packages_local);
check!(packages_local_fileoverride);
check!(override_remove);
check!(override_replace_local);
check!(initramfs);
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-builtin-deploy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ rpmostree_builtin_deploy (int argc,
NULL, /* refspec */
revision,
install_pkgs,
NULL, /* install_fileoverride_pkgs */
uninstall_pkgs,
NULL, /* override replace */
NULL, /* override remove */
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-builtin-rebase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ rpmostree_builtin_rebase (int argc,
new_provided_refspec,
revision,
install_pkgs,
NULL, /* install_fileoverride_pkgs */
uninstall_pkgs,
NULL, /* override replace */
NULL, /* override remove */
Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-reset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ rpmostree_builtin_reset (int argc,
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

if (!rpmostree_update_deployment (os_proxy, NULL, NULL, install_pkgs, uninstall_pkgs,
if (!rpmostree_update_deployment (os_proxy, NULL, NULL, install_pkgs, NULL, uninstall_pkgs,
NULL, NULL, NULL, NULL, options, &transaction_address,
cancellable, error))
return FALSE;
Expand Down
6 changes: 6 additions & 0 deletions src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
g_autofree const gchar **origin_requested_packages = NULL;
g_autofree const gchar **origin_requested_modules = NULL;
g_autofree const gchar **origin_requested_local_packages = NULL;
g_autofree const gchar **origin_requested_local_fileoverride_packages = NULL;
g_autoptr(GVariant) origin_base_removals = NULL;
g_autofree const gchar **origin_requested_base_removals = NULL;
g_autoptr(GVariant) origin_base_local_replacements = NULL;
Expand All @@ -585,6 +586,8 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
lookup_array_and_canonicalize (dict, "requested-modules");
origin_requested_local_packages =
lookup_array_and_canonicalize (dict, "requested-local-packages");
origin_requested_local_fileoverride_packages =
lookup_array_and_canonicalize (dict, "requested-local-fileoverride-packages");
origin_base_removals =
g_variant_dict_lookup_value (dict, "base-removals", G_VARIANT_TYPE ("av"));
origin_requested_base_removals =
Expand Down Expand Up @@ -963,6 +966,9 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
if (origin_requested_local_packages)
print_packages ("LocalPackages", max_key_len,
origin_requested_local_packages, NULL);
if (origin_requested_local_fileoverride_packages)
print_packages ("LocalForcedPackages", max_key_len,
origin_requested_local_fileoverride_packages, NULL);

if (regenerate_initramfs)
{
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-builtin-upgrade.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ rpmostree_builtin_upgrade (int argc,
NULL, /* refspec */
NULL, /* revision */
install_pkgs,
NULL, /* install_fileoverride_pkgs */
uninstall_pkgs,
NULL, /* override replace */
NULL, /* override remove */
Expand Down
17 changes: 14 additions & 3 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,13 @@ vardict_sort_and_insert_pkgs (GVariantDict *dict,
if (!rpmostree_sort_pkgs_strv (pkgs, fd_list, &repo_pkgs, &fd_idxs, error))
return FALSE;

/* for grep: here we insert install-packages/override-replace-packages */
/* for grep: here we insert install-packages/install-fileoverride-packages/override-replace-packages */
if (repo_pkgs != NULL && repo_pkgs->len > 0)
g_variant_dict_insert_value (dict, glnx_strjoina (key_prefix, "-packages"),
g_variant_new_strv ((const char *const*)repo_pkgs->pdata,
repo_pkgs->len));

/* for grep: here we insert install-local-packages/override-replace-local-packages */
/* for grep: here we insert install-local-packages/install-fileoverride-local-packages/override-replace-local-packages */
if (fd_idxs != NULL)
g_variant_dict_insert_value (dict, glnx_strjoina (key_prefix, "-local-packages"),
fd_idxs);
Expand All @@ -982,6 +982,7 @@ static gboolean
get_modifiers_variant (const char *set_refspec,
const char *set_revision,
const char *const* install_pkgs,
const char *const* install_fileoverride_pkgs,
const char *const* uninstall_pkgs,
const char *const* override_replace_pkgs,
const char *const* override_remove_pkgs,
Expand All @@ -1002,6 +1003,13 @@ get_modifiers_variant (const char *set_refspec,
return FALSE;
}

if (install_fileoverride_pkgs)
{
if (!vardict_sort_and_insert_pkgs (&dict, "install-fileoverride", fd_list,
install_fileoverride_pkgs, error))
return FALSE;
}

if (override_replace_pkgs)
{
if (!vardict_sort_and_insert_pkgs (&dict, "override-replace", fd_list,
Expand Down Expand Up @@ -1041,6 +1049,7 @@ rpmostree_update_deployment (RPMOSTreeOS *os_proxy,
const char *set_refspec,
const char *set_revision,
const char *const* install_pkgs,
const char *const* install_fileoverride_pkgs,
const char *const* uninstall_pkgs,
const char *const* override_replace_pkgs,
const char *const* override_remove_pkgs,
Expand All @@ -1054,7 +1063,9 @@ rpmostree_update_deployment (RPMOSTreeOS *os_proxy,
g_autoptr(GVariant) modifiers = NULL;
glnx_unref_object GUnixFDList *fd_list = NULL;
if (!get_modifiers_variant (set_refspec, set_revision,
install_pkgs, uninstall_pkgs,
install_pkgs,
install_fileoverride_pkgs,
uninstall_pkgs,
override_replace_pkgs,
override_remove_pkgs,
override_reset_pkgs,
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-clientlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ rpmostree_update_deployment (RPMOSTreeOS *os_proxy,
const char *set_refspec,
const char *set_revision,
const char *const* install_pkgs,
const char *const* install_fileoverride_pkgs,
const char *const* uninstall_pkgs,
const char *const* override_replace_pkgs,
const char *const* override_remove_pkgs,
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-override-builtins.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
NULL, /* set-refspec */
NULL, /* set-revision */
install_pkgs,
NULL, /* install_fileoverride_pkgs */
uninstall_pkgs,
override_replace,
override_remove,
Expand Down
10 changes: 8 additions & 2 deletions src/app/rpmostree-pkg-builtins.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static gboolean opt_allow_inactive;
static gboolean opt_uninstall_all;
static gboolean opt_unchanged_exit_77;
static gboolean opt_lock_finalization;
static gboolean opt_force_replacefiles;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -66,6 +67,7 @@ static GOptionEntry install_option_entry[] = {
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and RPM data", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Just download latest ostree and RPM data, don't deploy", NULL },
{ "apply-live", 'A', 0, G_OPTION_ARG_NONE, &opt_apply_live, "Apply changes to both pending deployment and running filesystem tree", NULL },
{ "force-replacefiles", 0, 0, G_OPTION_ARG_NONE, &opt_force_replacefiles, "Allow package to replace files from other packages", NULL },
{ NULL }
};

Expand All @@ -79,9 +81,12 @@ pkg_change (RpmOstreeCommandInvocation *invocation,
{
const char *const strv_empty[] = { NULL };
const char *const* install_pkgs = strv_empty;
const char *const* install_fileoverride_pkgs = strv_empty;
const char *const* uninstall_pkgs = strv_empty;

if (packages_to_add)
if (packages_to_add && opt_force_replacefiles)
install_fileoverride_pkgs = packages_to_add;
else if (packages_to_add && !opt_force_replacefiles)
install_pkgs = packages_to_add;
if (packages_to_remove)
uninstall_pkgs = packages_to_remove;
Expand Down Expand Up @@ -115,12 +120,13 @@ pkg_change (RpmOstreeCommandInvocation *invocation,

/* Use newer D-Bus API only if we have to. */
g_autofree char *transaction_address = NULL;
if (met_local_pkg || opt_apply_live)
if (met_local_pkg || opt_apply_live || (install_fileoverride_pkgs && *install_fileoverride_pkgs))
{
if (!rpmostree_update_deployment (os_proxy,
NULL, /* refspec */
NULL, /* revision */
install_pkgs,
install_fileoverride_pkgs,
uninstall_pkgs,
NULL, /* override replace */
NULL, /* override remove */
Expand Down
1 change: 1 addition & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"install-packages" (type 'as')
"uninstall-packages" (type 'as')
"install-local-packages" (type 'ah')
"install-local-fileoverride-packages" (type 'ah')
"install-modules" (type 'as')
"uninstall-modules" (type 'as')
"override-remove-packages" (type 'as')
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/rpmostree-sysroot-upgrader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ finalize_overlays (RpmOstreeSysrootUpgrader *self,
if (!add_local_pkgset_to_sack (self, local_pkgs, cancellable, error))
return FALSE;

GHashTable *local_fileoverride_pkgs = rpmostree_origin_get_local_fileoverride_packages (self->computed_origin);
if (!add_local_pkgset_to_sack (self, local_fileoverride_pkgs, cancellable, error))
return FALSE;

GHashTable *removals = rpmostree_origin_get_overrides_remove (self->computed_origin);

Expand Down
6 changes: 5 additions & 1 deletion src/daemon/rpmostreed-os.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ os_authorize_method (GDBusInterfaceSkeleton *interface,
g_autoptr(GVariant) install_local_pkgs =
g_variant_dict_lookup_value (&modifiers_dict, "install-local-packages",
G_VARIANT_TYPE("ah"));
g_autoptr(GVariant) install_local_fileoverride_pkgs =
g_variant_dict_lookup_value (&modifiers_dict, "install-local-fileoverride-packages",
G_VARIANT_TYPE("ah"));
g_autoptr(GVariant) override_replace_local_pkgs =
g_variant_dict_lookup_value (&modifiers_dict, "override-replace-local-packages",
G_VARIANT_TYPE("ah"));
Expand All @@ -216,7 +219,8 @@ os_authorize_method (GDBusInterfaceSkeleton *interface,
no_layering)
g_ptr_array_add (actions, (void*)"org.projectatomic.rpmostree1.install-uninstall-packages");

if (install_local_pkgs != NULL && g_variant_n_children (install_local_pkgs) > 0)
if ((install_local_pkgs != NULL && g_variant_n_children (install_local_pkgs) > 0)
|| (install_local_fileoverride_pkgs != NULL && g_variant_n_children (install_local_fileoverride_pkgs) > 0))
g_ptr_array_add (actions, (void*)"org.projectatomic.rpmostree1.install-local-packages");

if (override_replace_pkgs != NULL || override_remove_pkgs != NULL || override_reset_pkgs != NULL ||
Expand Down
Loading

0 comments on commit 6783b0a

Please sign in to comment.