add --preremove option
Allows adding and removing packages within a single transaction. This is particularly useful for complicated conflicts that ALPM cannot resolve on its own, e.g.: https://archlinux.org/news/linux-firmware-2025061312fe085f-5-upgrade-requires-manual-intervention/ Currently, dealing with these situations requires doing something complicated like bypassing dependency checking to break and then repair the database in two separate steps. By allowing installation and removal within a single transaction no bypass is required: pacman -Syu --preremove linux-firmware linux-firmware Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
45c4eef61d
commit
8b4f29af39
5 changed files with 29 additions and 1 deletions
|
@ -292,6 +292,9 @@ Upgrade Options (apply to '-S' and '-U')[[UO]]
|
||||||
exclamation mark. Subsequent matches will override previous ones. A leading
|
exclamation mark. Subsequent matches will override previous ones. A leading
|
||||||
literal exclamation mark or backslash needs to be escaped.
|
literal exclamation mark or backslash needs to be escaped.
|
||||||
|
|
||||||
|
*\--preremove <package>::
|
||||||
|
Uninstall 'package' before performing the requested installation. Multiple
|
||||||
|
packages can be specified by separating them with commas.
|
||||||
|
|
||||||
Query Options (apply to '-Q')[[QO]]
|
Query Options (apply to '-Q')[[QO]]
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
|
@ -150,6 +150,7 @@ int config_free(config_t *oldconfig)
|
||||||
FREELIST(oldconfig->noupgrade);
|
FREELIST(oldconfig->noupgrade);
|
||||||
FREELIST(oldconfig->noextract);
|
FREELIST(oldconfig->noextract);
|
||||||
FREELIST(oldconfig->overwrite_files);
|
FREELIST(oldconfig->overwrite_files);
|
||||||
|
FREELIST(oldconfig->preremove);
|
||||||
free(oldconfig->configfile);
|
free(oldconfig->configfile);
|
||||||
free(oldconfig->sysroot);
|
free(oldconfig->sysroot);
|
||||||
free(oldconfig->rootdir);
|
free(oldconfig->rootdir);
|
||||||
|
|
|
@ -134,6 +134,8 @@ typedef struct __config_t {
|
||||||
/* our connection to libalpm */
|
/* our connection to libalpm */
|
||||||
alpm_handle_t *handle;
|
alpm_handle_t *handle;
|
||||||
|
|
||||||
|
alpm_list_t *preremove;
|
||||||
|
|
||||||
alpm_list_t *explicit_adds;
|
alpm_list_t *explicit_adds;
|
||||||
alpm_list_t *explicit_removes;
|
alpm_list_t *explicit_removes;
|
||||||
|
|
||||||
|
@ -214,7 +216,8 @@ enum {
|
||||||
OP_REFRESH,
|
OP_REFRESH,
|
||||||
OP_ASSUMEINSTALLED,
|
OP_ASSUMEINSTALLED,
|
||||||
OP_DISABLEDLTIMEOUT,
|
OP_DISABLEDLTIMEOUT,
|
||||||
OP_DISABLESANDBOX
|
OP_DISABLESANDBOX,
|
||||||
|
OP_PREREMOVE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* clean method */
|
/* clean method */
|
||||||
|
|
|
@ -196,6 +196,8 @@ static void usage(int op, const char * const myname)
|
||||||
addlist(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
|
addlist(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
|
||||||
addlist(_(" --ignoregroup <grp>\n"
|
addlist(_(" --ignoregroup <grp>\n"
|
||||||
" ignore a group upgrade (can be used more than once)\n"));
|
" ignore a group upgrade (can be used more than once)\n"));
|
||||||
|
addlist(_(" --preremove <pkg>\n"));
|
||||||
|
addlist(_(" uninstall <pkg> before performing installation\n"));
|
||||||
__attribute__((fallthrough));
|
__attribute__((fallthrough));
|
||||||
case PM_OP_REMOVE:
|
case PM_OP_REMOVE:
|
||||||
addlist(_(" -d, --nodeps skip dependency version checks (-dd to skip all checks)\n"));
|
addlist(_(" -d, --nodeps skip dependency version checks (-dd to skip all checks)\n"));
|
||||||
|
@ -770,6 +772,9 @@ static int parsearg_upgrade(int opt)
|
||||||
case OP_IGNOREGROUP:
|
case OP_IGNOREGROUP:
|
||||||
parsearg_util_addlist(&(config->ignoregrp));
|
parsearg_util_addlist(&(config->ignoregrp));
|
||||||
break;
|
break;
|
||||||
|
case OP_PREREMOVE:
|
||||||
|
parsearg_util_addlist(&(config->preremove));
|
||||||
|
break;
|
||||||
case OP_DOWNLOADONLY:
|
case OP_DOWNLOADONLY:
|
||||||
case 'w':
|
case 'w':
|
||||||
config->op_s_downloadonly = 1;
|
config->op_s_downloadonly = 1;
|
||||||
|
@ -982,6 +987,7 @@ static int parseargs(int argc, char *argv[])
|
||||||
{"color", required_argument, 0, OP_COLOR},
|
{"color", required_argument, 0, OP_COLOR},
|
||||||
{"disable-download-timeout", no_argument, 0, OP_DISABLEDLTIMEOUT},
|
{"disable-download-timeout", no_argument, 0, OP_DISABLEDLTIMEOUT},
|
||||||
{"disable-sandbox", no_argument, 0, OP_DISABLESANDBOX},
|
{"disable-sandbox", no_argument, 0, OP_DISABLESANDBOX},
|
||||||
|
{"preremove", required_argument, 0, OP_PREREMOVE},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -717,6 +717,21 @@ static int sync_trans(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i = config->preremove; i; i = i->next) {
|
||||||
|
alpm_pkg_t *pkg;
|
||||||
|
const char *pname = i->data;
|
||||||
|
alpm_db_t *db_local = alpm_get_localdb(config->handle);
|
||||||
|
|
||||||
|
if((pkg = alpm_db_get_pkg(db_local, pname)) != NULL) {
|
||||||
|
if(alpm_remove_pkg(config->handle, pkg) == -1) {
|
||||||
|
alpm_errno_t err = alpm_errno(config->handle);
|
||||||
|
pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", pname, alpm_strerror(err));
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
|
config->explicit_removes = alpm_list_add(config->explicit_removes, pkg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(retval) {
|
if(retval) {
|
||||||
trans_release();
|
trans_release();
|
||||||
return retval;
|
return retval;
|
||||||
|
|
Loading…
Add table
Reference in a new issue