Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install --force-replacefiles #3125

Merged
merged 6 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 18 additions & 10 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 @@ -78,11 +80,16 @@ pkg_change (RpmOstreeCommandInvocation *invocation,
GError **error)
{
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)
packages_to_add = strv_empty;
if (!packages_to_remove)
packages_to_remove = strv_empty;
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;

glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname,
Expand All @@ -109,17 +116,18 @@ pkg_change (RpmOstreeCommandInvocation *invocation,

gboolean met_local_pkg = FALSE;
for (const char *const* it = packages_to_add; it && *it; it++)
met_local_pkg = met_local_pkg || g_str_has_suffix (*it, ".rpm");
met_local_pkg = met_local_pkg || g_str_has_suffix (*it, ".rpm") || g_str_has_prefix (*it, "file://");

/* 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 */
packages_to_add,
packages_to_remove,
install_pkgs,
install_fileoverride_pkgs,
uninstall_pkgs,
NULL, /* override replace */
NULL, /* override remove */
NULL, /* override reset */
Expand All @@ -134,8 +142,8 @@ pkg_change (RpmOstreeCommandInvocation *invocation,
{
if (!rpmostree_os_call_pkg_change_sync (os_proxy,
options,
packages_to_add,
packages_to_remove,
install_pkgs,
uninstall_pkgs,
NULL,
&transaction_address,
NULL,
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
76 changes: 46 additions & 30 deletions src/daemon/rpmostree-sysroot-upgrader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,47 @@ finalize_overrides (RpmOstreeSysrootUpgrader *self,
&& finalize_replacement_overrides (self, cancellable, error);
}

static gboolean
add_local_pkgset_to_sack (RpmOstreeSysrootUpgrader *self,
GHashTable *pkgset,
GCancellable *cancellable,
GError **error)
{
if (g_hash_table_size (pkgset) == 0)
return TRUE; /* nothing to do! */

if (!initialize_metatmpdir (self, error))
return FALSE;

GLNX_HASH_TABLE_FOREACH_KV (pkgset, const char*, nevra, const char*, sha256)
{
g_autoptr(GVariant) header = NULL;
g_autofree char *path =
g_strdup_printf ("%s/%s.rpm", self->metatmpdir.path, nevra);

if (!rpmostree_pkgcache_find_pkg_header (self->repo, nevra, sha256,
&header, cancellable, error))
return FALSE;

if (!glnx_file_replace_contents_at (AT_FDCWD, path,
static_cast<const guint8*>(g_variant_get_data (header)),
g_variant_get_size (header),
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
return FALSE;

/* Also check if that exact NEVRA is already in the root (if the pkg
* exists, but is a different EVR, depsolve will catch that). In the
* future, we'll allow packages to replace base pkgs. */
if (rpmostree_sack_has_subject (self->rsack->sack, nevra))
return glnx_throw (error, "Package '%s' is already in the base", nevra);

dnf_sack_add_cmdline_package (self->rsack->sack, path);
}

return TRUE;
}

/* Go through rpmdb and jot down the missing pkgs from the given set. Really, we
* don't *have* to do this: we could just give everything to libdnf and let it
* figure out what is already installed. The advantage of doing it ourselves is
Expand All @@ -804,37 +845,12 @@ finalize_overlays (RpmOstreeSysrootUpgrader *self,
* you can have foo-1.0-1.x86_64 layered, and foo or /usr/bin/foo as dormant.
* */
GHashTable *local_pkgs = rpmostree_origin_get_local_packages (self->computed_origin);
if (g_hash_table_size (local_pkgs) > 0)
{
if (!initialize_metatmpdir (self, error))
return FALSE;

GLNX_HASH_TABLE_FOREACH_KV (local_pkgs, const char*, nevra, const char*, sha256)
{
g_autoptr(GVariant) header = NULL;
g_autofree char *path =
g_strdup_printf ("%s/%s.rpm", self->metatmpdir.path, nevra);

if (!rpmostree_pkgcache_find_pkg_header (self->repo, nevra, sha256,
&header, cancellable, error))
return FALSE;

if (!glnx_file_replace_contents_at (AT_FDCWD, path,
static_cast<const guint8*>(g_variant_get_data (header)),
g_variant_get_size (header),
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
return FALSE;

/* Also check if that exact NEVRA is already in the root (if the pkg
* exists, but is a different EVR, depsolve will catch that). In the
* future, we'll allow packages to replace base pkgs. */
if (rpmostree_sack_has_subject (self->rsack->sack, nevra))
return glnx_throw (error, "Package '%s' is already in the base", nevra);
if (!add_local_pkgset_to_sack (self, local_pkgs, cancellable, error))
return FALSE;

dnf_sack_add_cmdline_package (self->rsack->sack, path);
}
}
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
Loading