[pacman-dev] [PATCH] Move -Sy operation into its own transaction

Xavier shiningxc at gmail.com
Mon Feb 18 06:56:10 EST 2008


On Mon, Feb 18, 2008 at 12:15:37AM -0600, Dan McGee wrote:
> > 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)\n"),
> > +                       alpm_strerrorlast());
> > +               if(pm_errno == PM_ERR_HANDLE_LOCK) {
> > +                       printf(_("  if you're sure a package manager is not already\n"
> > +                                "  running, you can remove %s.\n"), alpm_option_get_lockfile());
> > +               }
> > +               return(0);
> > +       }
> > +
> 
> Don't we have this same code in a few different places now? Can we
> refactor this somehow?
> 

I will see what I can do.

> >         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)\n"),
> > +                       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\n"));
> > +       }
> >         return(success > 0);
> >  }
> >


Well, it simply refers to that last part.
If at least one DB was upgraded (success > 0), we return 1.
Otherwise (success = 0), we print an error and return 0.




More information about the pacman-dev mailing list