jobcore/pacman/sync_first_option.patch
2022-03-20 14:19:37 +02:00

114 lines
3.6 KiB
Diff

diff -Nuar -uar a/src/pacman/conf.c b/src/pacman/conf.c
--- a/src/pacman/conf.c 2020-06-22 19:33:22.000000000 +1100
+++ b/src/pacman/conf.c 2020-12-24 20:01:21.885850894 +1100
@@ -137,6 +137,7 @@
alpm_list_free(config->repos);
FREELIST(oldconfig->holdpkg);
+ FREELIST(oldconfig->syncfirst);
FREELIST(oldconfig->ignorepkg);
FREELIST(oldconfig->ignoregrp);
FREELIST(oldconfig->assumeinstalled);
@@ -598,6 +599,8 @@
setrepeatingoption(value, "IgnoreGroup", &(config->ignoregrp));
} else if(strcmp(key, "HoldPkg") == 0) {
setrepeatingoption(value, "HoldPkg", &(config->holdpkg));
+ } else if(strcmp(key, "SyncFirst") == 0) {
+ setrepeatingoption(value, "SyncFirst", &(config->syncfirst));
} else if(strcmp(key, "CacheDir") == 0) {
setrepeatingoption(value, "CacheDir", &(config->cachedirs));
} else if(strcmp(key, "HookDir") == 0) {
diff -Nuar -uar a/src/pacman/conf.h b/src/pacman/conf.h
--- a/src/pacman/conf.h 2020-06-22 19:33:22.000000000 +1100
+++ b/src/pacman/conf.h 2020-12-24 20:01:38.349183872 +1100
@@ -118,6 +118,7 @@
/* select -Sc behavior */
unsigned short cleanmethod;
alpm_list_t *holdpkg;
+ alpm_list_t *syncfirst;
alpm_list_t *ignorepkg;
alpm_list_t *ignoregrp;
alpm_list_t *assumeinstalled;
diff -Nuar -uar a/src/pacman/sync.c b/src/pacman/sync.c
--- a/src/pacman/sync.c 2020-06-22 19:33:22.000000000 +1100
+++ b/src/pacman/sync.c 2020-12-24 20:03:25.629181556 +1100
@@ -540,6 +540,26 @@
return 0;
}
+static alpm_list_t *syncfirst(void) {
+ alpm_list_t *i, *res = NULL;
+ alpm_db_t *db_local = alpm_get_localdb(config->handle);
+ alpm_list_t *syncdbs = alpm_get_syncdbs(config->handle);
+
+ for(i = config->syncfirst; i; i = alpm_list_next(i)) {
+ const char *pkgname = i->data;
+ alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
+ if(pkg == NULL) {
+ continue;
+ }
+
+ if(alpm_sync_get_new_version(pkg, syncdbs)) {
+ res = alpm_list_add(res, strdup(pkgname));
+ }
+ }
+
+ return res;
+}
+
static int process_group(alpm_list_t *dbs, const char *group, int error)
{
int ret = 0;
@@ -945,5 +965,52 @@
}
}
+ /* check for syncfirsts */
+ if(!config->op_s_downloadonly && !config->print) {
+ /* check for newer versions of packages to be upgraded first */
+ alpm_list_t *i, *j, *syncfirsts = syncfirst();
+ if(syncfirsts) {
+ /* Do not ask user if all the -S targets are SyncFirst packages, see FS#15810 */
+ alpm_list_t *targets_diff = alpm_list_diff(targets, syncfirsts, (alpm_list_fn_cmp)strcmp);
+ if(config->op_s_upgrade || targets_diff) {
+ int syncfirst_ret = 1;
+ colon_printf(_("Some packages should be upgraded first...\n"));
+ if(trans_init(0, 1) == 0) {
+ for(i = syncfirsts; i; i = alpm_list_next(i)) {
+ syncfirst_ret = process_targname(alpm_get_syncdbs(config->handle), i->data, 0);
+ if (syncfirst_ret == 1) {
+ break;
+ }
+ }
+ }
+ if (syncfirst_ret == 0) {
+ syncfirst_ret = sync_prepare_execute();
+ } else {
+ trans_release();
+ }
+ if (syncfirst_ret == 0) {
+ /* reinitialize handle to take care of changes */
+ parseconfig(config->configfile);
+ /* remove syncfirsts from targets */
+ alpm_list_t *i = targets;
+ while(i) {
+ for(j = syncfirsts; j; j = alpm_list_next(j)) {
+ if(strcmp(i->data, j->data) == 0) {
+ targets = alpm_list_remove_item(targets, i);
+ break;
+ }
+ }
+ i = i->next;
+ }
+ }
+ printf("\n");
+ } else {
+ pm_printf(ALPM_LOG_DEBUG, "skipping SyncFirst\n");
+ }
+ alpm_list_free(targets_diff);
+ FREELIST(syncfirsts);
+ }
+ }
+
return sync_trans(targets);
}