Skip to content

Commit

Permalink
Native support for core package updates.
Browse files Browse the repository at this point in the history
System upgrade is now split into two steps. Core packages are updated first and
control is not returned to shell (unless --noconfirm is specified). When no core
update is required then normal update process takes place.

Therefore, full system update is now more straightforward by simply executing
--sysupgrade twice. The update process is now also scriptable from external
environments like batch files.
  • Loading branch information
renatosilva committed Mar 29, 2016
1 parent c08074b commit 6e0ff83
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/libalpm/alpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,9 @@ int alpm_trans_release(alpm_handle_t *handle);
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade);
#ifdef __MSYS__
int alpm_sync_sysupgrade_core(alpm_handle_t *handle, int enable_downgrade);
#endif

/** Add a package to the transaction.
* If the package was loaded by alpm_pkg_load(), it will be freed upon
Expand Down
30 changes: 30 additions & 0 deletions lib/libalpm/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ static alpm_list_t *check_replacers(alpm_handle_t *handle, alpm_pkg_t *lpkg,
}

/** Search for packages to upgrade and add them to the transaction. */
#ifdef __MSYS__
static
int SYMEXPORT do_alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade, int core_update)
#else
int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
#endif
{
alpm_list_t *i, *j;
alpm_trans_t *trans;
Expand All @@ -214,6 +219,19 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) {
alpm_pkg_t *lpkg = i->data;

#ifdef __MSYS__
if(core_update
&& strcmp(lpkg->name, "bash") != 0
&& strcmp(lpkg->name, "filesystem") != 0
&& strcmp(lpkg->name, "mintty") != 0
&& strcmp(lpkg->name, "msys2-runtime") != 0
&& strcmp(lpkg->name, "msys2-runtime-devel") != 0
&& strcmp(lpkg->name, "pacman") != 0
&& strcmp(lpkg->name, "pacman-mirrors") != 0) {
continue;
}
#endif

if(alpm_pkg_find(trans->remove, lpkg->name)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is marked for removal -- skipping\n", lpkg->name);
continue;
Expand Down Expand Up @@ -255,6 +273,18 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
return 0;
}

#ifdef __MSYS__
int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
{
return do_alpm_sync_sysupgrade(handle, enable_downgrade, 0);
}

int SYMEXPORT alpm_sync_sysupgrade_core(alpm_handle_t *handle, int enable_downgrade)
{
return do_alpm_sync_sysupgrade(handle, enable_downgrade, 1);
}
#endif

/** Find group members across a list of databases.
* If a member exists in several databases, only the first database is used.
* IgnorePkg is also handled.
Expand Down
14 changes: 14 additions & 0 deletions src/pacman/sighandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <signal.h>
#include <unistd.h>

#ifdef __MSYS__
#include <termios.h>
#endif

#include <alpm.h>

#include "conf.h"
Expand All @@ -44,6 +48,9 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
*/
static void soft_interrupt_handler(int signum)
{
#ifdef __MSYS__
struct termios term;
#endif
if(signum == SIGINT) {
const char msg[] = "\nInterrupt signal received\n";
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
Expand All @@ -56,6 +63,13 @@ static void soft_interrupt_handler(int signum)
return;
}
alpm_unlock(config->handle);
#ifdef __MSYS__
/* restore input printing possibly disabled by core update */
if(tcgetattr(STDIN_FILENO, &term) == 0) {
term.c_lflag |= ECHO;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
}
#endif
/* output a newline to be sure we clear any line we may be on */
xwrite(STDOUT_FILENO, "\n", 1);
_Exit(128 + signum);
Expand Down
66 changes: 66 additions & 0 deletions src/pacman/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <sys/stat.h>
#include <fnmatch.h>

#ifdef __MSYS__
#include <termios.h>
#endif

#include <alpm.h>
#include <alpm_list.h>

Expand Down Expand Up @@ -670,8 +674,62 @@ static int process_target(const char *target, int error)
return ret;
}

#ifdef __MSYS__
static int wait_indefinitely(void)
{
struct termios term;

/* disable input printing */
if(tcgetattr(STDIN_FILENO, &term) == 0) {
term.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
}

while (1) {
getchar();
}
}

static int core_update(int *needed)
{
int retval;

colon_printf(_("Starting core system upgrade...\n"));
alpm_logaction(config->handle, PACMAN_CALLER_PREFIX,
"starting core system upgrade\n");

if(alpm_sync_sysupgrade_core(config->handle, config->op_s_upgrade >= 2) == -1) {
pm_printf(ALPM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle)));
trans_release();
return 1;
}

if(!(*needed = alpm_trans_get_add(config->handle) != NULL)) {
if (!config->print) {
printf(_(" there is nothing to do\n"));
}
return 0;
}

pm_printf(ALPM_LOG_WARNING, _("terminate other MSYS2 programs before proceeding\n"));
if((retval = sync_prepare_execute()) == 0) {
pm_printf(ALPM_LOG_WARNING, _("terminate MSYS2 without returning to shell and check for updates again\n"));
pm_printf(ALPM_LOG_WARNING, _("for example close your terminal window instead of calling exit"));
if(config->noconfirm) {
fprintf(stdout, "\n");
return 0;
}
wait_indefinitely();
}
return retval;
}
#endif

static int sync_trans(alpm_list_t *targets)
{
#ifdef __MSYS__
int found_core_updates = 0;
#endif
int retval = 0;
alpm_list_t *i;

Expand All @@ -694,6 +752,14 @@ static int sync_trans(alpm_list_t *targets)
}

if(config->op_s_upgrade) {
#ifdef __MSYS__
if(retval = core_update(&found_core_updates)) {
return retval;
}
if(found_core_updates) {
return retval;
}
#endif
colon_printf(_("Starting full system upgrade...\n"));
alpm_logaction(config->handle, PACMAN_CALLER_PREFIX,
"starting full system upgrade\n");
Expand Down

0 comments on commit 6e0ff83

Please sign in to comment.