4 * Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #include <alpm_list.h>
40 static int unlink_verbose(const char *pathname
, int ignore_missing
)
42 int ret
= unlink(pathname
);
44 if(ignore_missing
&& errno
== ENOENT
) {
47 pm_printf(ALPM_LOG_ERROR
, _("could not remove %s: %s\n"),
48 pathname
, strerror(errno
));
54 /* if keep_used != 0, then the db files which match an used syncdb
56 static int sync_cleandb(const char *dbpath
, int keep_used
)
63 dir
= opendir(dbpath
);
65 pm_printf(ALPM_LOG_ERROR
, _("could not access database directory\n"));
69 syncdbs
= alpm_get_syncdbs(config
->handle
);
72 /* step through the directory one file at a time */
73 while((ent
= readdir(dir
)) != NULL
) {
77 const char *dname
= ent
->d_name
;
81 if(strcmp(dname
, ".") == 0 || strcmp(dname
, "..") == 0) {
84 /* skip the local and sync directories */
85 if(strcmp(dname
, "sync") == 0 || strcmp(dname
, "local") == 0) {
88 /* skip the db.lck file */
89 if(strcmp(dname
, "db.lck") == 0) {
93 /* build the full path */
94 snprintf(path
, PATH_MAX
, "%s%s", dbpath
, dname
);
96 /* remove all non-skipped directories and non-database files */
98 if(S_ISDIR(buf
.st_mode
)) {
100 pm_printf(ALPM_LOG_ERROR
, _("could not remove %s: %s\n"),
101 path
, strerror(errno
));
107 if(len
> 3 && strcmp(dname
+ len
- 3, ".db") == 0) {
108 dbname
= strndup(dname
, len
- 3);
109 } else if(len
> 7 && strcmp(dname
+ len
- 7, ".db.sig") == 0) {
110 dbname
= strndup(dname
, len
- 7);
112 ret
+= unlink_verbose(path
, 0);
118 for(i
= syncdbs
; i
&& !found
; i
= alpm_list_next(i
)) {
119 alpm_db_t
*db
= i
->data
;
120 found
= !strcmp(dbname
, alpm_db_get_name(db
));
124 /* We have a database that doesn't match any syncdb. */
126 /* ENOENT check is because the signature and database could come in any
127 * order in our readdir() call, so either file may already be gone. */
128 snprintf(path
, PATH_MAX
, "%s%s.db", dbpath
, dbname
);
129 ret
+= unlink_verbose(path
, 1);
130 /* unlink a signature file if present too */
131 snprintf(path
, PATH_MAX
, "%s%s.db.sig", dbpath
, dbname
);
132 ret
+= unlink_verbose(path
, 1);
140 static int sync_cleandb_all(void)
146 dbpath
= alpm_option_get_dbpath(config
->handle
);
147 printf(_("Database directory: %s\n"), dbpath
);
148 if(!yesno(_("Do you want to remove unused repositories?"))) {
151 printf(_("removing unused sync repositories...\n"));
152 /* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
153 * We will clean everything in dbpath/ except local/, sync/ and db.lck, and
154 * only the unused sync dbs in dbpath/sync/ */
155 ret
+= sync_cleandb(dbpath
, 0);
157 if(asprintf(&newdbpath
, "%s%s", dbpath
, "sync/") < 0) {
161 ret
+= sync_cleandb(newdbpath
, 1);
167 static int sync_cleancache(int level
)
170 alpm_list_t
*sync_dbs
= alpm_get_syncdbs(config
->handle
);
171 alpm_db_t
*db_local
= alpm_get_localdb(config
->handle
);
172 alpm_list_t
*cachedirs
= alpm_option_get_cachedirs(config
->handle
);
175 for(i
= cachedirs
; i
; i
= alpm_list_next(i
)) {
176 printf(_("Cache directory: %s\n"), (const char *)i
->data
);
179 if(!config
->cleanmethod
) {
180 /* default to KeepInstalled if user did not specify */
181 config
->cleanmethod
= PM_CLEAN_KEEPINST
;
185 printf(_("Packages to keep:\n"));
186 if(config
->cleanmethod
& PM_CLEAN_KEEPINST
) {
187 printf(_(" All locally installed packages\n"));
189 if(config
->cleanmethod
& PM_CLEAN_KEEPCUR
) {
190 printf(_(" All current sync database packages\n"));
192 if(!yesno(_("Do you want to remove all other packages from cache?"))) {
195 printf(_("removing old packages from cache...\n"));
197 if(!noyes(_("Do you want to remove ALL files from cache?"))) {
200 printf(_("removing all files from cache...\n"));
203 for(i
= cachedirs
; i
; i
= alpm_list_next(i
)) {
204 const char *cachedir
= i
->data
;
205 DIR *dir
= opendir(cachedir
);
209 pm_printf(ALPM_LOG_ERROR
,
210 _("could not access cache directory %s\n"), cachedir
);
216 /* step through the directory one file at a time */
217 while((ent
= readdir(dir
)) != NULL
) {
220 alpm_pkg_t
*localpkg
= NULL
, *pkg
= NULL
;
221 const char *local_name
, *local_version
;
223 if(strcmp(ent
->d_name
, ".") == 0 || strcmp(ent
->d_name
, "..") == 0) {
227 /* skip signature files - they are removed with their package file */
228 if(fnmatch("*.sig", ent
->d_name
, 0) == 0) {
232 /* skip package database within the cache directory */
233 if(fnmatch("*.db*", ent
->d_name
, 0) == 0) {
237 /* skip source packages within the cache directory */
238 if(fnmatch("*.src.tar*", ent
->d_name
, 0) == 0) {
242 /* build the full filepath */
243 snprintf(path
, PATH_MAX
, "%s%s", cachedir
, ent
->d_name
);
245 /* short circuit for removing all files from cache */
247 ret
+= unlink_verbose(path
, 0);
251 /* attempt to load the file as a package. if we cannot load the file,
252 * simply skip it and move on. we don't need a full load of the package,
253 * just the metadata. */
254 if(alpm_pkg_load(config
->handle
, path
, 0, 0, &localpkg
) != 0) {
255 pm_printf(ALPM_LOG_DEBUG
, "skipping %s, could not load as package\n",
259 local_name
= alpm_pkg_get_name(localpkg
);
260 local_version
= alpm_pkg_get_version(localpkg
);
262 if(config
->cleanmethod
& PM_CLEAN_KEEPINST
) {
263 /* check if this package is in the local DB */
264 pkg
= alpm_db_get_pkg(db_local
, local_name
);
265 if(pkg
!= NULL
&& alpm_pkg_vercmp(local_version
,
266 alpm_pkg_get_version(pkg
)) == 0) {
267 /* package was found in local DB and version matches, keep it */
268 pm_printf(ALPM_LOG_DEBUG
, "package %s-%s found in local db\n",
269 local_name
, local_version
);
273 if(config
->cleanmethod
& PM_CLEAN_KEEPCUR
) {
275 /* check if this package is in a sync DB */
276 for(j
= sync_dbs
; j
&& delete; j
= alpm_list_next(j
)) {
277 alpm_db_t
*db
= j
->data
;
278 pkg
= alpm_db_get_pkg(db
, local_name
);
279 if(pkg
!= NULL
&& alpm_pkg_vercmp(local_version
,
280 alpm_pkg_get_version(pkg
)) == 0) {
281 /* package was found in a sync DB and version matches, keep it */
282 pm_printf(ALPM_LOG_DEBUG
, "package %s-%s found in sync db\n",
283 local_name
, local_version
);
288 /* free the local file package */
289 alpm_pkg_free(localpkg
);
292 size_t pathlen
= strlen(path
);
293 ret
+= unlink_verbose(path
, 0);
294 /* unlink a signature file if present too */
295 if(PATH_MAX
- 5 >= pathlen
) {
296 strcpy(path
+ pathlen
, ".sig");
297 ret
+= unlink_verbose(path
, 1);
307 static int sync_synctree(int level
, alpm_list_t
*syncs
)
310 unsigned int success
= 0;
312 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
313 alpm_db_t
*db
= i
->data
;
315 int ret
= alpm_db_update((level
< 2 ? 0 : 1), db
);
317 pm_printf(ALPM_LOG_ERROR
, _("failed to update %s (%s)\n"),
318 alpm_db_get_name(db
), alpm_strerror(alpm_errno(config
->handle
)));
319 } else if(ret
== 1) {
320 printf(_(" %s is up to date\n"), alpm_db_get_name(db
));
327 /* We should always succeed if at least one DB was upgraded - we may possibly
328 * fail later with unresolved deps, but that should be rare, and would be
332 pm_printf(ALPM_LOG_ERROR
, _("failed to synchronize any databases\n"));
335 return (success
> 0);
338 static void print_installed(alpm_db_t
*db_local
, alpm_pkg_t
*pkg
)
340 const char *pkgname
= alpm_pkg_get_name(pkg
);
341 const char *pkgver
= alpm_pkg_get_version(pkg
);
342 alpm_pkg_t
*lpkg
= alpm_db_get_pkg(db_local
, pkgname
);
344 const char *lpkgver
= alpm_pkg_get_version(lpkg
);
345 if(strcmp(lpkgver
,pkgver
) == 0) {
346 printf(" [%s]", _("installed"));
348 printf(" [%s: %s]", _("installed"), lpkgver
);
353 /* search the sync dbs for a matching package */
354 static int sync_search(alpm_list_t
*syncs
, alpm_list_t
*targets
)
356 alpm_list_t
*i
, *j
, *ret
;
359 alpm_db_t
*db_local
= alpm_get_localdb(config
->handle
);
361 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
362 alpm_db_t
*db
= i
->data
;
364 /* if we have a targets list, search for packages matching it */
366 ret
= alpm_db_search(db
, targets
);
369 ret
= alpm_db_get_pkgcache(db
);
377 cols
= getcols(fileno(stdout
));
378 for(j
= ret
; j
; j
= alpm_list_next(j
)) {
380 alpm_pkg_t
*pkg
= j
->data
;
383 printf("%s/%s %s", alpm_db_get_name(db
), alpm_pkg_get_name(pkg
),
384 alpm_pkg_get_version(pkg
));
386 fputs(alpm_pkg_get_name(pkg
), stdout
);
390 if((grp
= alpm_pkg_get_groups(pkg
)) != NULL
) {
393 for(k
= grp
; k
; k
= alpm_list_next(k
)) {
394 const char *group
= k
->data
;
395 fputs(group
, stdout
);
396 if(alpm_list_next(k
)) {
397 /* only print a spacer if there are more groups */
404 print_installed(db_local
, pkg
);
406 /* we need a newline and initial indent first */
407 fputs("\n ", stdout
);
408 indentprint(alpm_pkg_get_desc(pkg
), 4, cols
);
412 /* we only want to free if the list was a search list */
421 static int sync_group(int level
, alpm_list_t
*syncs
, alpm_list_t
*targets
)
423 alpm_list_t
*i
, *j
, *k
, *s
= NULL
;
426 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
427 const char *grpname
= i
->data
;
428 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
429 alpm_db_t
*db
= j
->data
;
430 alpm_group_t
*grp
= alpm_db_get_group(db
, grpname
);
433 /* get names of packages in group */
434 for(k
= grp
->packages
; k
; k
= alpm_list_next(k
)) {
436 printf("%s %s\n", grpname
,
437 alpm_pkg_get_name(k
->data
));
439 printf("%s\n", alpm_pkg_get_name(k
->data
));
446 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
447 alpm_db_t
*db
= i
->data
;
449 for(j
= alpm_db_get_groupcache(db
); j
; j
= alpm_list_next(j
)) {
450 alpm_group_t
*grp
= j
->data
;
453 for(k
= grp
->packages
; k
; k
= alpm_list_next(k
)) {
454 printf("%s %s\n", grp
->name
,
455 alpm_pkg_get_name(k
->data
));
458 /* print grp names only, no package names */
459 if(!alpm_list_find_str (s
, grp
->name
)) {
460 s
= alpm_list_add (s
, grp
->name
);
461 printf("%s\n", grp
->name
);
472 static int sync_info(alpm_list_t
*syncs
, alpm_list_t
*targets
)
474 alpm_list_t
*i
, *j
, *k
;
478 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
479 const char *target
= i
->data
;
480 char *name
= strdup(target
);
482 int foundpkg
= 0, founddb
= 0;
484 pkgstr
= strchr(name
, '/');
494 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
495 alpm_db_t
*db
= j
->data
;
496 if(repo
&& strcmp(repo
, alpm_db_get_name(db
)) != 0) {
501 for(k
= alpm_db_get_pkgcache(db
); k
; k
= alpm_list_next(k
)) {
502 alpm_pkg_t
*pkg
= k
->data
;
504 if(strcmp(alpm_pkg_get_name(pkg
), pkgstr
) == 0) {
505 dump_pkg_full(pkg
, config
->op_s_info
> 1);
513 pm_printf(ALPM_LOG_ERROR
,
514 _("repository '%s' does not exist\n"), repo
);
518 pm_printf(ALPM_LOG_ERROR
,
519 _("package '%s' was not found\n"), target
);
525 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
526 alpm_db_t
*db
= i
->data
;
528 for(j
= alpm_db_get_pkgcache(db
); j
; j
= alpm_list_next(j
)) {
529 alpm_pkg_t
*pkg
= j
->data
;
530 dump_pkg_full(pkg
, config
->op_s_info
> 1);
538 static int sync_list(alpm_list_t
*syncs
, alpm_list_t
*targets
)
540 alpm_list_t
*i
, *j
, *ls
= NULL
;
541 alpm_db_t
*db_local
= alpm_get_localdb(config
->handle
);
544 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
545 const char *repo
= i
->data
;
546 alpm_db_t
*db
= NULL
;
548 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
549 alpm_db_t
*d
= j
->data
;
551 if(strcmp(repo
, alpm_db_get_name(d
)) == 0) {
558 pm_printf(ALPM_LOG_ERROR
,
559 _("repository \"%s\" was not found.\n"),repo
);
564 ls
= alpm_list_add(ls
, db
);
570 for(i
= ls
; i
; i
= alpm_list_next(i
)) {
571 alpm_db_t
*db
= i
->data
;
573 for(j
= alpm_db_get_pkgcache(db
); j
; j
= alpm_list_next(j
)) {
574 alpm_pkg_t
*pkg
= j
->data
;
577 printf("%s %s %s", alpm_db_get_name(db
), alpm_pkg_get_name(pkg
),
578 alpm_pkg_get_version(pkg
));
579 print_installed(db_local
, pkg
);
582 printf("%s\n", alpm_pkg_get_name(pkg
));
594 static alpm_list_t
*syncfirst(void) {
595 alpm_list_t
*i
, *res
= NULL
;
596 alpm_db_t
*db_local
= alpm_get_localdb(config
->handle
);
597 alpm_list_t
*syncdbs
= alpm_get_syncdbs(config
->handle
);
599 for(i
= config
->syncfirst
; i
; i
= alpm_list_next(i
)) {
600 const char *pkgname
= i
->data
;
601 alpm_pkg_t
*pkg
= alpm_db_get_pkg(db_local
, pkgname
);
606 if(alpm_sync_newversion(pkg
, syncdbs
)) {
607 res
= alpm_list_add(res
, strdup(pkgname
));
614 static alpm_db_t
*get_db(const char *dbname
)
617 for(i
= alpm_get_syncdbs(config
->handle
); i
; i
= i
->next
) {
618 alpm_db_t
*db
= i
->data
;
619 if(strcmp(alpm_db_get_name(db
), dbname
) == 0) {
626 static int process_pkg(alpm_pkg_t
*pkg
)
628 int ret
= alpm_add_pkg(config
->handle
, pkg
);
631 alpm_errno_t err
= alpm_errno(config
->handle
);
632 if(err
== ALPM_ERR_TRANS_DUP_TARGET
633 || err
== ALPM_ERR_PKG_IGNORED
) {
634 /* just skip duplicate or ignored targets */
635 pm_printf(ALPM_LOG_WARNING
, _("skipping target: %s\n"), alpm_pkg_get_name(pkg
));
638 pm_printf(ALPM_LOG_ERROR
, "'%s': %s\n", alpm_pkg_get_name(pkg
),
643 config
->explicit_adds
= alpm_list_add(config
->explicit_adds
, pkg
);
647 static int process_group(alpm_list_t
*dbs
, const char *group
, int error
)
651 alpm_list_t
*pkgs
= alpm_find_group_pkgs(dbs
, group
);
652 int count
= alpm_list_count(pkgs
);
655 pm_printf(ALPM_LOG_ERROR
, _("target not found: %s\n"), group
);
660 /* we already know another target errored. there is no reason to prompt the
661 * user here; we already validated the group name so just move on since we
662 * won't actually be installing anything anyway. */
666 if(config
->print
== 0) {
667 printf(_(":: There are %d members in group %s:\n"), count
,
669 select_display(pkgs
);
670 char *array
= malloc(count
);
675 if(multiselect_question(array
, count
)) {
681 for(i
= pkgs
; i
; i
= alpm_list_next(i
)) {
684 alpm_pkg_t
*pkg
= i
->data
;
686 if(process_pkg(pkg
) == 1) {
694 for(i
= pkgs
; i
; i
= alpm_list_next(i
)) {
695 alpm_pkg_t
*pkg
= i
->data
;
697 if(process_pkg(pkg
) == 1) {
705 alpm_list_free(pkgs
);
709 static int process_targname(alpm_list_t
*dblist
, const char *targname
,
712 alpm_pkg_t
*pkg
= alpm_find_dbs_satisfier(config
->handle
, dblist
, targname
);
714 /* #FS#23342 - skip ignored packages when user says no */
715 if(alpm_errno(config
->handle
) == ALPM_ERR_PKG_IGNORED
) {
716 pm_printf(ALPM_LOG_WARNING
, _("skipping target: %s\n"), targname
);
721 return process_pkg(pkg
);
723 /* fallback on group */
724 return process_group(dblist
, targname
, error
);
727 static int process_target(const char *target
, int error
)
729 /* process targets */
730 char *targstring
= strdup(target
);
731 char *targname
= strchr(targstring
, '/');
735 if(targname
&& targname
!= targstring
) {
744 pm_printf(ALPM_LOG_ERROR
, _("database not found: %s\n"),
749 dblist
= alpm_list_add(NULL
, db
);
750 ret
= process_targname(dblist
, targname
, error
);
751 alpm_list_free(dblist
);
753 targname
= targstring
;
754 dblist
= alpm_get_syncdbs(config
->handle
);
755 ret
= process_targname(dblist
, targname
, error
);
760 if(ret
&& access(target
, R_OK
) == 0) {
761 pm_printf(ALPM_LOG_WARNING
,
762 _("'%s' is a file, did you mean %s instead of %s?\n"),
763 target
, "-U/--upgrade", "-S/--sync");
768 static int sync_trans(alpm_list_t
*targets
)
773 /* Step 1: create a new transaction... */
774 if(trans_init(config
->flags
, 1) == -1) {
778 /* process targets */
779 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
780 const char *targ
= i
->data
;
781 if(process_target(targ
, retval
) == 1) {
791 if(config
->op_s_upgrade
) {
792 printf(_(":: Starting full system upgrade...\n"));
793 alpm_logaction(config
->handle
, "starting full system upgrade\n");
794 if(alpm_sync_sysupgrade(config
->handle
, config
->op_s_upgrade
>= 2) == -1) {
795 pm_printf(ALPM_LOG_ERROR
, "%s\n", alpm_strerror(alpm_errno(config
->handle
)));
801 return sync_prepare_execute();
804 int sync_prepare_execute(void)
806 alpm_list_t
*i
, *packages
, *data
= NULL
;
809 /* Step 2: "compute" the transaction based on targets and flags */
810 if(alpm_trans_prepare(config
->handle
, &data
) == -1) {
811 alpm_errno_t err
= alpm_errno(config
->handle
);
812 pm_printf(ALPM_LOG_ERROR
, _("failed to prepare transaction (%s)\n"),
815 case ALPM_ERR_PKG_INVALID_ARCH
:
816 for(i
= data
; i
; i
= alpm_list_next(i
)) {
817 const char *pkg
= i
->data
;
818 printf(_(":: package %s does not have a valid architecture\n"), pkg
);
821 case ALPM_ERR_UNSATISFIED_DEPS
:
822 for(i
= data
; i
; i
= alpm_list_next(i
)) {
823 alpm_depmissing_t
*miss
= i
->data
;
824 char *depstring
= alpm_dep_compute_string(miss
->depend
);
825 printf(_(":: %s: requires %s\n"), miss
->target
, depstring
);
829 case ALPM_ERR_CONFLICTING_DEPS
:
830 for(i
= data
; i
; i
= alpm_list_next(i
)) {
831 alpm_conflict_t
*conflict
= i
->data
;
832 /* only print reason if it contains new information */
833 if(conflict
->reason
->mod
== ALPM_DEP_MOD_ANY
) {
834 printf(_(":: %s and %s are in conflict\n"),
835 conflict
->package1
, conflict
->package2
);
837 char *reason
= alpm_dep_compute_string(conflict
->reason
);
838 printf(_(":: %s and %s are in conflict (%s)\n"),
839 conflict
->package1
, conflict
->package2
, reason
);
851 packages
= alpm_trans_get_add(config
->handle
);
852 if(packages
== NULL
) {
853 /* nothing to do: just exit without complaining */
855 printf(_(" there is nothing to do\n"));
860 /* Step 3: actually perform the operation */
862 print_packages(packages
);
870 if(config
->op_s_downloadonly
) {
871 confirm
= yesno(_("Proceed with download?"));
873 confirm
= yesno(_("Proceed with installation?"));
879 if(alpm_trans_commit(config
->handle
, &data
) == -1) {
880 alpm_errno_t err
= alpm_errno(config
->handle
);
881 pm_printf(ALPM_LOG_ERROR
, _("failed to commit transaction (%s)\n"),
884 case ALPM_ERR_FILE_CONFLICTS
:
885 for(i
= data
; i
; i
= alpm_list_next(i
)) {
886 alpm_fileconflict_t
*conflict
= i
->data
;
887 switch(conflict
->type
) {
888 case ALPM_FILECONFLICT_TARGET
:
889 printf(_("%s exists in both '%s' and '%s'\n"),
890 conflict
->file
, conflict
->target
, conflict
->ctarget
);
892 case ALPM_FILECONFLICT_FILESYSTEM
:
893 printf(_("%s: %s exists in filesystem\n"),
894 conflict
->target
, conflict
->file
);
899 case ALPM_ERR_PKG_INVALID
:
900 case ALPM_ERR_PKG_INVALID_CHECKSUM
:
901 case ALPM_ERR_PKG_INVALID_SIG
:
902 case ALPM_ERR_DLT_INVALID
:
903 for(i
= data
; i
; i
= alpm_list_next(i
)) {
904 const char *filename
= i
->data
;
905 printf(_("%s is invalid or corrupted\n"), filename
);
912 printf(_("Errors occurred, no packages were upgraded.\n"));
917 /* Step 4: release transaction resources */
922 if(trans_release() == -1) {
929 int pacman_sync(alpm_list_t
*targets
)
931 alpm_list_t
*sync_dbs
= NULL
;
933 /* clean the cache */
934 if(config
->op_s_clean
) {
937 if(trans_init(0, 0) == -1) {
941 ret
+= sync_cleancache(config
->op_s_clean
);
943 ret
+= sync_cleandb_all();
945 if(trans_release() == -1) {
952 if(check_syncdbs(1, 0)) {
956 sync_dbs
= alpm_get_syncdbs(config
->handle
);
958 if(config
->op_s_sync
) {
959 /* grab a fresh package list */
960 printf(_(":: Synchronizing package databases...\n"));
961 alpm_logaction(config
->handle
, "synchronizing package lists\n");
962 if(!sync_synctree(config
->op_s_sync
, sync_dbs
)) {
967 if(check_syncdbs(1, 1)) {
971 /* search for a package */
972 if(config
->op_s_search
) {
973 return sync_search(sync_dbs
, targets
);
976 /* look for groups */
978 return sync_group(config
->group
, sync_dbs
, targets
);
981 /* get package info */
982 if(config
->op_s_info
) {
983 return sync_info(sync_dbs
, targets
);
986 /* get a listing of files in sync DBs */
987 if(config
->op_q_list
) {
988 return sync_list(sync_dbs
, targets
);
991 if(targets
== NULL
) {
992 if(config
->op_s_upgrade
) {
994 } else if(config
->op_s_sync
) {
997 /* don't proceed here unless we have an operation that doesn't require a
999 pm_printf(ALPM_LOG_ERROR
, _("no targets specified (use -h for help)\n"));
1004 alpm_list_t
*targs
= alpm_list_strdup(targets
);
1005 if(!config
->op_s_downloadonly
&& !config
->print
) {
1006 /* check for newer versions of packages to be upgraded first */
1007 alpm_list_t
*packages
= syncfirst();
1009 /* Do not ask user if all the -S targets are SyncFirst packages, see FS#15810 */
1010 alpm_list_t
*tmp
= NULL
;
1011 if(config
->op_s_upgrade
|| (tmp
= alpm_list_diff(targets
, packages
, (alpm_list_fn_cmp
)strcmp
))) {
1012 alpm_list_free(tmp
);
1013 printf(_(":: The following packages should be upgraded first :\n"));
1014 list_display(" ", packages
, getcols(fileno(stdout
)));
1015 if(yesno(_(":: Do you want to cancel the current operation\n"
1016 ":: and upgrade these packages now?"))) {
1020 config
->op_s_upgrade
= 0;
1026 pm_printf(ALPM_LOG_DEBUG
, "skipping SyncFirst dialog\n");
1032 int ret
= sync_trans(targs
);
1038 /* vim: set ts=2 sw=2 noet: */