FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 02-17-2008, 02:12 PM
Chantry Xavier
 
Default Move -Sy operation into its own transaction

This allows us to remove the sync_only flag, and also do the following
steps in the future :
1) refresh the database (if asked)
2) do other stuff (eg checking if a newer pacman version is available)
3) start the actual transaction

Currently when we detect a newer pacman version, we have to release the
current transaction and start a new one.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
---
src/pacman/sync.c | 56 ++++++++++++++++++++++++++++++++--------------------
1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 27218d6..bb2a8bb 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -202,6 +202,17 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_list_t *i;
int success = 0, ret;

+ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, 0, cb_trans_evt,
+ cb_trans_conv, cb_trans_progress) == -1) {
+ fprintf(stderr, _("error: failed to init transaction (%s)
"),
+ alpm_strerrorlast());
+ if(pm_errno == PM_ERR_HANDLE_LOCK) {
+ printf(_(" if you're sure a package manager is not already
"
+ " running, you can remove %s.
"), alpm_option_get_lockfile());
+ }
+ return(0);
+ }
+
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);

@@ -229,10 +240,18 @@ static int sync_synctree(int level, alpm_list_t *syncs)
}
}

+ if(alpm_trans_release() == -1) {
+ fprintf(stderr, _("error: failed to release transaction (%s)
"),
+ alpm_strerrorlast());
+ return(0);
+ }
/* We should always succeed if at least one DB was upgraded - we may possibly
* fail later with unresolved deps, but that should be rare, and would be
* expected
*/
+ if(!success) {
+ fprintf(stderr, _("error: failed to synchronize any databases
"));
+ }
return(success > 0);
}

@@ -469,7 +488,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
return(0);
}

-static int sync_trans(alpm_list_t *targets, int sync_only)
+static int sync_trans(alpm_list_t *targets)
{
int retval = 0;
alpm_list_t *data = NULL;
@@ -487,23 +506,8 @@ static int sync_trans(alpm_list_t *targets, int sync_only)
return(1);
}

- if(config->op_s_sync) {
- /* grab a fresh package list */
- printf(_(":: Synchronizing package databases...
"));
- alpm_logaction("synchronizing package lists
");
- if(!sync_synctree(config->op_s_sync, sync_dbs)) {
- fprintf(stderr, _("error: failed to synchronize any databases
"));
- retval = 1;
- goto cleanup;
- }
- if(sync_only) {
- goto cleanup;
- }
- }
-
if(config->op_s_upgrade) {
alpm_list_t *pkgs, *i;
-
printf(_(":: Starting full system upgrade...
"));
alpm_logaction("starting full system upgrade
");
if(alpm_trans_sysupgrade() == -1) {
@@ -756,7 +760,6 @@ cleanup:
int pacman_sync(alpm_list_t *targets)
{
alpm_list_t *sync_dbs = NULL;
- int sync_only = 0;

/* clean the cache */
if(config->op_s_clean) {
@@ -772,18 +775,27 @@ int pacman_sync(alpm_list_t *targets)
return(1);
}

- if(config->op_s_search || config->group
- || config->op_s_info || config->op_q_list) {
- sync_only = 1;
- } else if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
+ if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade
+ || config->op_s_search || config->group
+ || config->op_s_info || config->op_q_list)) {
/* don't proceed here unless we have an operation that doesn't require
* a target list */
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)
"));
return(1);
}

+ if(config->op_s_sync) {
+ /* grab a fresh package list */
+ printf(_(":: Synchronizing package databases...
"));
+ alpm_logaction("synchronizing package lists
");
+ if(!sync_synctree(config->op_s_sync, sync_dbs)) {
+ return(1);
+ }
+ config->op_s_sync = 0;
+ }
+
if(needs_transaction()) {
- if(sync_trans(targets, sync_only) == 1) {
+ if(sync_trans(targets) == 1) {
return(1);
}
}
--
1.5.4


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 02-18-2008, 05:15 AM
"Dan McGee"
 
Default Move -Sy operation into its own transaction

On Feb 17, 2008 9:12 AM, Chantry Xavier <shiningxc@gmail.com> wrote:
> This allows us to remove the sync_only flag, and also do the following
> steps in the future :
> 1) refresh the database (if asked)
> 2) do other stuff (eg checking if a newer pacman version is available)
> 3) start the actual transaction
>
> Currently when we detect a newer pacman version, we have to release the
> current transaction and start a new one.

Looks good to me, I like this way of thinking.

> Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
> ---
> src/pacman/sync.c | 56 ++++++++++++++++++++++++++++++++--------------------
> 1 files changed, 34 insertions(+), 22 deletions(-)
>
> diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> index 27218d6..bb2a8bb 100644
> --- a/src/pacman/sync.c
> +++ b/src/pacman/sync.c
> @@ -202,6 +202,17 @@ static int sync_synctree(int level, alpm_list_t *syncs)
> alpm_list_t *i;
> int success = 0, ret;
>
> + if(alpm_trans_init(PM_TRANS_TYPE_SYNC, 0, cb_trans_evt,
> + cb_trans_conv, cb_trans_progress) == -1) {
> + fprintf(stderr, _("error: failed to init transaction (%s)
"),
> + alpm_strerrorlast());
> + if(pm_errno == PM_ERR_HANDLE_LOCK) {
> + printf(_(" if you're sure a package manager is not already
"
> + " running, you can remove %s.
"), alpm_option_get_lockfile());
> + }
> + return(0);
> + }
> +

Don't we have this same code in a few different places now? Can we
refactor this somehow?

> for(i = syncs; i; i = alpm_list_next(i)) {
> pmdb_t *db = alpm_list_getdata(i);
>
> @@ -229,10 +240,18 @@ static int sync_synctree(int level, alpm_list_t *syncs)
> }
> }
>
> + if(alpm_trans_release() == -1) {
> + fprintf(stderr, _("error: failed to release transaction (%s)
"),
> + alpm_strerrorlast());
> + return(0);
> + }
> /* We should always succeed if at least one DB was upgraded - we may possibly
> * fail later with unresolved deps, but that should be rare, and would be
> * expected
> */
What is this comment even referring to? I'm confused here. And you had
code changes on either side of it.

> + if(!success) {
> + fprintf(stderr, _("error: failed to synchronize any databases
"));
> + }
> return(success > 0);
> }
>
> @@ -469,7 +488,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
> return(0);
> }
>
> -static int sync_trans(alpm_list_t *targets, int sync_only)
> +static int sync_trans(alpm_list_t *targets)
> {
> int retval = 0;
> alpm_list_t *data = NULL;
> @@ -487,23 +506,8 @@ static int sync_trans(alpm_list_t *targets, int sync_only)
> return(1);
> }
>
> - if(config->op_s_sync) {
> - /* grab a fresh package list */
> - printf(_(":: Synchronizing package databases...
"));
> - alpm_logaction("synchronizing package lists
");
> - if(!sync_synctree(config->op_s_sync, sync_dbs)) {
> - fprintf(stderr, _("error: failed to synchronize any databases
"));
> - retval = 1;
> - goto cleanup;
> - }
> - if(sync_only) {
> - goto cleanup;
> - }
> - }
> -
> if(config->op_s_upgrade) {
> alpm_list_t *pkgs, *i;
> -
> printf(_(":: Starting full system upgrade...
"));
> alpm_logaction("starting full system upgrade
");
> if(alpm_trans_sysupgrade() == -1) {
> @@ -756,7 +760,6 @@ cleanup:
> int pacman_sync(alpm_list_t *targets)
> {
> alpm_list_t *sync_dbs = NULL;
> - int sync_only = 0;
>
> /* clean the cache */
> if(config->op_s_clean) {
> @@ -772,18 +775,27 @@ int pacman_sync(alpm_list_t *targets)
> return(1);
> }
>
> - if(config->op_s_search || config->group
> - || config->op_s_info || config->op_q_list) {
> - sync_only = 1;
> - } else if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
> + if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade
> + || config->op_s_search || config->group
> + || config->op_s_info || config->op_q_list)) {
> /* don't proceed here unless we have an operation that doesn't require
> * a target list */
> pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)
"));
> return(1);
> }
>
> + if(config->op_s_sync) {
> + /* grab a fresh package list */
> + printf(_(":: Synchronizing package databases...
"));
> + alpm_logaction("synchronizing package lists
");
> + if(!sync_synctree(config->op_s_sync, sync_dbs)) {
> + return(1);
> + }
> + config->op_s_sync = 0;
> + }
> +
> if(needs_transaction()) {
> - if(sync_trans(targets, sync_only) == 1) {
> + if(sync_trans(targets) == 1) {
> return(1);
> }
> }
> --
> 1.5.4

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 02-18-2008, 01:14 PM
Chantry Xavier
 
Default Move -Sy operation into its own transaction

This allows us to remove the sync_only flag, and also do the following
steps in the future :
1) refresh the database (if asked)
2) do other stuff (eg checking if a newer pacman version is available)
3) start the actual transaction

Currently when we detect a newer pacman version, we have to release the
current transaction and start a new one.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
---
src/pacman/sync.c | 97 +++++++++++++++++++++++++++++------------------------
1 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 27218d6..c4c4090 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -197,11 +197,37 @@ static int sync_cleancache(int level)
return(0);
}

+static int sync_trans_init(pmtransflag_t flags) {
+ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, flags, cb_trans_evt,
+ cb_trans_conv, cb_trans_progress) == -1) {
+ fprintf(stderr, _("error: failed to init transaction (%s)
"),
+ alpm_strerrorlast());
+ if(pm_errno == PM_ERR_HANDLE_LOCK) {
+ printf(_(" if you're sure a package manager is not already
"
+ " running, you can remove %s.
"), alpm_option_get_lockfile());
+ }
+ return(-1);
+ }
+ return(0);
+}
+
+static int sync_trans_release() {
+ if(alpm_trans_release() == -1) {
+ fprintf(stderr, _("error: failed to release transaction (%s)
"),
+ alpm_strerrorlast());
+ return(-1);
+ }
+ return(0);
+}
static int sync_synctree(int level, alpm_list_t *syncs)
{
alpm_list_t *i;
int success = 0, ret;

+ if(sync_trans_init(0) == -1) {
+ return(0);
+ }
+
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);

@@ -229,10 +255,16 @@ static int sync_synctree(int level, alpm_list_t *syncs)
}
}

+ if(sync_trans_release() == -1) {
+ return(0);
+ }
/* We should always succeed if at least one DB was upgraded - we may possibly
* fail later with unresolved deps, but that should be rare, and would be
* expected
*/
+ if(!success) {
+ fprintf(stderr, _("error: failed to synchronize any databases
"));
+ }
return(success > 0);
}

@@ -469,41 +501,19 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
return(0);
}

-static int sync_trans(alpm_list_t *targets, int sync_only)
+static int sync_trans(alpm_list_t *targets)
{
int retval = 0;
alpm_list_t *data = NULL;
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();

/* Step 1: create a new transaction... */
- if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
- cb_trans_conv, cb_trans_progress) == -1) {
- fprintf(stderr, _("error: failed to init transaction (%s)
"),
- alpm_strerrorlast());
- if(pm_errno == PM_ERR_HANDLE_LOCK) {
- printf(_(" if you're sure a package manager is not already
"
- " running, you can remove %s.
"), alpm_option_get_lockfile());
- }
+ if(sync_trans_init(config->flags) == -1) {
return(1);
}

- if(config->op_s_sync) {
- /* grab a fresh package list */
- printf(_(":: Synchronizing package databases...
"));
- alpm_logaction("synchronizing package lists
");
- if(!sync_synctree(config->op_s_sync, sync_dbs)) {
- fprintf(stderr, _("error: failed to synchronize any databases
"));
- retval = 1;
- goto cleanup;
- }
- if(sync_only) {
- goto cleanup;
- }
- }
-
if(config->op_s_upgrade) {
alpm_list_t *pkgs, *i;
-
printf(_(":: Starting full system upgrade...
"));
alpm_logaction("starting full system upgrade
");
if(alpm_trans_sysupgrade() == -1) {
@@ -529,22 +539,15 @@ static int sync_trans(alpm_list_t *targets, int sync_only)
printf(_(":: pacman has detected a newer version of itself.
"));
if(yesno(_(":: Do you want to cancel the current operation
"
":: and install the new pacman version now? [Y/n] "))) {
- if(alpm_trans_release() == -1) {
- fprintf(stderr, _("error: failed to release transaction (%s)
"),
- alpm_strerrorlast());
- retval = 1;
- goto cleanup;
+ if(sync_trans_release() == -1) {
+ return(1);
}
- if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags,
- cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
- fprintf(stderr, _("error: failed to init transaction (%s)
"),
- alpm_strerrorlast());
+ if(sync_trans_init(0) == -1) {
return(1);
}
if(alpm_trans_addtarget("pacman") == -1) {
fprintf(stderr, _("error: pacman: %s
"), alpm_strerrorlast());
- retval = 1;
- goto cleanup;
+ return(1);
}
break;
}
@@ -744,9 +747,7 @@ cleanup:
if(data) {
FREELIST(data);
}
- if(alpm_trans_release() == -1) {
- fprintf(stderr, _("error: failed to release transaction (%s)
"),
- alpm_strerrorlast());
+ if(sync_trans_release() == -1) {
retval = 1;
}

@@ -756,7 +757,6 @@ cleanup:
int pacman_sync(alpm_list_t *targets)
{
alpm_list_t *sync_dbs = NULL;
- int sync_only = 0;

/* clean the cache */
if(config->op_s_clean) {
@@ -772,18 +772,27 @@ int pacman_sync(alpm_list_t *targets)
return(1);
}

- if(config->op_s_search || config->group
- || config->op_s_info || config->op_q_list) {
- sync_only = 1;
- } else if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
+ if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade
+ || config->op_s_search || config->group
+ || config->op_s_info || config->op_q_list)) {
/* don't proceed here unless we have an operation that doesn't require
* a target list */
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)
"));
return(1);
}

+ if(config->op_s_sync) {
+ /* grab a fresh package list */
+ printf(_(":: Synchronizing package databases...
"));
+ alpm_logaction("synchronizing package lists
");
+ if(!sync_synctree(config->op_s_sync, sync_dbs)) {
+ return(1);
+ }
+ config->op_s_sync = 0;
+ }
+
if(needs_transaction()) {
- if(sync_trans(targets, sync_only) == 1) {
+ if(sync_trans(targets) == 1) {
return(1);
}
}
--
1.5.4.2


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 05:48 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org