4 * Copyright (c) 2006-2011 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 /* if keep_used != 0, then the db files which match an used syncdb
42 static int sync_cleandb(const char *dbpath
, int keep_used
) {
47 dir
= opendir(dbpath
);
49 pm_fprintf(stderr
, PM_LOG_ERROR
, _("could not access database directory\n"));
53 syncdbs
= alpm_option_get_syncdbs();
56 /* step through the directory one file at a time */
57 while((ent
= readdir(dir
)) != NULL
) {
61 const char *dname
= ent
->d_name
;
64 if(strcmp(dname
, ".") == 0 || strcmp(dname
, "..") == 0) {
67 /* skip the local and sync directories */
68 if(strcmp(dname
, "sync") == 0 || strcmp(dname
, "local") == 0) {
71 /* skip the db.lck file */
72 if(strcmp(dname
, "db.lck") == 0) {
76 /* build the full path */
77 snprintf(path
, PATH_MAX
, "%s%s", dbpath
, dname
);
79 /* remove all non-skipped directories and non-database files */
82 if(S_ISDIR(buf
.st_mode
) || strcmp(path
+ len
- 3, ".db") != 0) {
84 pm_fprintf(stderr
, PM_LOG_ERROR
,
85 _("could not remove %s\n"), path
);
95 char *dbname
= strndup(dname
, len
- 3);
96 for(i
= syncdbs
; i
&& !found
; i
= alpm_list_next(i
)) {
97 pmdb_t
*db
= alpm_list_getdata(i
);
98 found
= !strcmp(dbname
, alpm_db_get_name(db
));
102 /* We have a database that doesn't match any syncdb.
103 * Ask the user if he wants to remove it. */
105 if(!yesno(_("Do you want to remove %s?"), path
)) {
110 pm_fprintf(stderr
, PM_LOG_ERROR
,
111 _("could not remove %s\n"), path
);
121 static int sync_cleandb_all(void) {
123 char newdbpath
[PATH_MAX
];
126 dbpath
= alpm_option_get_dbpath();
127 printf(_("Database directory: %s\n"), dbpath
);
128 if(!yesno(_("Do you want to remove unused repositories?"))) {
131 /* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
132 * We will clean everything in dbpath/ except local/, sync/ and db.lck, and
133 * only the unused sync dbs in dbpath/sync/ */
134 ret
+= sync_cleandb(dbpath
, 0);
136 sprintf(newdbpath
, "%s%s", dbpath
, "sync/");
137 ret
+= sync_cleandb(newdbpath
, 1);
139 printf(_("Database directory cleaned up\n"));
143 static int sync_cleancache(int level
)
146 alpm_list_t
*sync_dbs
= alpm_option_get_syncdbs();
147 pmdb_t
*db_local
= alpm_option_get_localdb();
150 for(i
= alpm_option_get_cachedirs(); i
; i
= alpm_list_next(i
)) {
151 printf(_("Cache directory: %s\n"), (char*)alpm_list_getdata(i
));
154 if(!config
->cleanmethod
) {
155 /* default to KeepInstalled if user did not specify */
156 config
->cleanmethod
= PM_CLEAN_KEEPINST
;
160 printf(_("Packages to keep:\n"));
161 if(config
->cleanmethod
& PM_CLEAN_KEEPINST
) {
162 printf(_(" All locally installed packages\n"));
164 if(config
->cleanmethod
& PM_CLEAN_KEEPCUR
) {
165 printf(_(" All current sync database packages\n"));
167 if(!yesno(_("Do you want to remove all other packages from cache?"))) {
170 printf(_("removing old packages from cache...\n"));
172 if(!noyes(_("Do you want to remove ALL files from cache?"))) {
175 printf(_("removing all files from cache...\n"));
178 for(i
= alpm_option_get_cachedirs(); i
; i
= alpm_list_next(i
)) {
179 const char *cachedir
= alpm_list_getdata(i
);
180 DIR *dir
= opendir(cachedir
);
184 pm_fprintf(stderr
, PM_LOG_ERROR
,
185 _("could not access cache directory %s\n"), cachedir
);
191 /* step through the directory one file at a time */
192 while((ent
= readdir(dir
)) != NULL
) {
195 pmpkg_t
*localpkg
= NULL
, *pkg
= NULL
;
196 const char *local_name
, *local_version
;
199 if(strcmp(ent
->d_name
, ".") == 0 || strcmp(ent
->d_name
, "..") == 0) {
202 /* build the full filepath */
203 snprintf(path
, PATH_MAX
, "%s%s", cachedir
, ent
->d_name
);
205 /* short circuit for removing all packages from cache */
211 /* attempt to load the package, prompt removal on failures as we may have
212 * files here that aren't valid packages. we also don't need a full
213 * load of the package, just the metadata. */
214 if(alpm_pkg_load(path
, 0, &localpkg
) != 0 || localpkg
== NULL
) {
215 if(yesno(_("File %s does not seem to be a valid package, remove it?"), path
)) {
217 alpm_pkg_free(localpkg
);
223 local_name
= alpm_pkg_get_name(localpkg
);
224 local_version
= alpm_pkg_get_version(localpkg
);
226 if(config
->cleanmethod
& PM_CLEAN_KEEPINST
) {
227 /* check if this package is in the local DB */
228 pkg
= alpm_db_get_pkg(db_local
, local_name
);
229 if(pkg
!= NULL
&& alpm_pkg_vercmp(local_version
,
230 alpm_pkg_get_version(pkg
)) == 0) {
231 /* package was found in local DB and version matches, keep it */
232 pm_printf(PM_LOG_DEBUG
, "pkg %s-%s found in local db\n",
233 local_name
, local_version
);
237 if(config
->cleanmethod
& PM_CLEAN_KEEPCUR
) {
238 /* check if this package is in a sync DB */
239 for(j
= sync_dbs
; j
&& delete; j
= alpm_list_next(j
)) {
240 pmdb_t
*db
= alpm_list_getdata(j
);
241 pkg
= alpm_db_get_pkg(db
, local_name
);
242 if(pkg
!= NULL
&& alpm_pkg_vercmp(local_version
,
243 alpm_pkg_get_version(pkg
)) == 0) {
244 /* package was found in a sync DB and version matches, keep it */
245 pm_printf(PM_LOG_DEBUG
, "pkg %s-%s found in sync db\n",
246 local_name
, local_version
);
251 /* free the local file package */
252 alpm_pkg_free(localpkg
);
264 static int sync_synctree(int level
, alpm_list_t
*syncs
)
267 int success
= 0, ret
;
269 if(trans_init(0) == -1) {
273 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
274 pmdb_t
*db
= alpm_list_getdata(i
);
276 ret
= alpm_db_update((level
< 2 ? 0 : 1), db
);
278 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to update %s (%s)\n"),
279 alpm_db_get_name(db
), alpm_strerrorlast());
280 } else if(ret
== 1) {
281 printf(_(" %s is up to date\n"), alpm_db_get_name(db
));
288 if(trans_release() == -1) {
291 /* We should always succeed if at least one DB was upgraded - we may possibly
292 * fail later with unresolved deps, but that should be rare, and would be
296 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to synchronize any databases\n"));
301 static void print_installed(pmdb_t
*db_local
, pmpkg_t
*pkg
)
303 const char *pkgname
= alpm_pkg_get_name(pkg
);
304 const char *pkgver
= alpm_pkg_get_version(pkg
);
305 pmpkg_t
*lpkg
= alpm_db_get_pkg(db_local
, pkgname
);
307 const char *lpkgver
= alpm_pkg_get_version(lpkg
);
308 if(strcmp(lpkgver
,pkgver
) == 0) {
309 printf(" [%s]", _("installed"));
311 printf(" [%s: %s]", _("installed"), lpkgver
);
316 /* search the sync dbs for a matching package */
317 static int sync_search(alpm_list_t
*syncs
, alpm_list_t
*targets
)
319 alpm_list_t
*i
, *j
, *ret
;
322 pmdb_t
*db_local
= alpm_option_get_localdb();
324 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
325 pmdb_t
*db
= alpm_list_getdata(i
);
326 /* if we have a targets list, search for packages matching it */
328 ret
= alpm_db_search(db
, targets
);
331 ret
= alpm_db_get_pkgcache(db
);
339 for(j
= ret
; j
; j
= alpm_list_next(j
)) {
341 pmpkg_t
*pkg
= alpm_list_getdata(j
);
343 if (!config
->quiet
) {
344 printf("%s/%s %s", alpm_db_get_name(db
), alpm_pkg_get_name(pkg
),
345 alpm_pkg_get_version(pkg
));
347 printf("%s", alpm_pkg_get_name(pkg
));
350 /* print the package size with the output if ShowSize option set */
351 if(!config
->quiet
&& config
->showsize
) {
352 /* Convert byte size to MB */
353 double mbsize
= (double)alpm_pkg_get_size(pkg
) / (1024.0 * 1024.0);
355 printf(" [%.2f MB]", mbsize
);
358 if (!config
->quiet
) {
359 if((grp
= alpm_pkg_get_groups(pkg
)) != NULL
) {
362 for(k
= grp
; k
; k
= alpm_list_next(k
)) {
363 const char *group
= alpm_list_getdata(k
);
365 if(alpm_list_next(k
)) {
366 /* only print a spacer if there are more groups */
373 print_installed(db_local
, pkg
);
375 /* we need a newline and initial indent first */
377 indentprint(alpm_pkg_get_desc(pkg
), 4);
381 /* we only want to free if the list was a search list */
390 static int sync_group(int level
, alpm_list_t
*syncs
, alpm_list_t
*targets
)
392 alpm_list_t
*i
, *j
, *k
;
395 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
396 const char *grpname
= alpm_list_getdata(i
);
397 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
398 pmdb_t
*db
= alpm_list_getdata(j
);
399 pmgrp_t
*grp
= alpm_db_readgrp(db
, grpname
);
402 /* get names of packages in group */
403 for(k
= alpm_grp_get_pkgs(grp
); k
; k
= alpm_list_next(k
)) {
405 printf("%s %s\n", grpname
,
406 alpm_pkg_get_name(alpm_list_getdata(k
)));
408 printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(k
)));
415 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
416 pmdb_t
*db
= alpm_list_getdata(i
);
418 for(j
= alpm_db_get_grpcache(db
); j
; j
= alpm_list_next(j
)) {
419 pmgrp_t
*grp
= alpm_list_getdata(j
);
420 const char *grpname
= alpm_grp_get_name(grp
);
423 for(k
= alpm_grp_get_pkgs(grp
); k
; k
= alpm_list_next(k
)) {
424 printf("%s %s\n", grpname
,
425 alpm_pkg_get_name(alpm_list_getdata(k
)));
428 /* print grp names only, no package names */
429 printf("%s\n", grpname
);
438 static int sync_info(alpm_list_t
*syncs
, alpm_list_t
*targets
)
440 alpm_list_t
*i
, *j
, *k
;
444 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
448 char target
[512]; /* TODO is this enough space? */
449 char *repo
= NULL
, *pkgstr
= NULL
;
451 strncpy(target
, i
->data
, 512);
452 pkgstr
= strchr(target
, '/');
458 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
459 db
= alpm_list_getdata(j
);
460 if(strcmp(repo
, alpm_db_get_name(db
)) == 0) {
467 pm_fprintf(stderr
, PM_LOG_ERROR
,
468 _("repository '%s' does not exist\n"), repo
);
472 for(k
= alpm_db_get_pkgcache(db
); k
; k
= alpm_list_next(k
)) {
473 pmpkg_t
*pkg
= alpm_list_getdata(k
);
475 if(strcmp(alpm_pkg_get_name(pkg
), pkgstr
) == 0) {
476 dump_pkg_sync(pkg
, alpm_db_get_name(db
), config
->op_s_info
);
483 pm_fprintf(stderr
, PM_LOG_ERROR
,
484 _("package '%s' was not found in repository '%s'\n"), pkgstr
, repo
);
490 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
491 pmdb_t
*db
= alpm_list_getdata(j
);
493 for(k
= alpm_db_get_pkgcache(db
); k
; k
= alpm_list_next(k
)) {
494 pmpkg_t
*pkg
= alpm_list_getdata(k
);
496 if(strcmp(alpm_pkg_get_name(pkg
), pkgstr
) == 0) {
497 dump_pkg_sync(pkg
, alpm_db_get_name(db
), config
->op_s_info
);
504 pm_fprintf(stderr
, PM_LOG_ERROR
,
505 _("package '%s' was not found\n"), pkgstr
);
511 for(i
= syncs
; i
; i
= alpm_list_next(i
)) {
512 pmdb_t
*db
= alpm_list_getdata(i
);
514 for(j
= alpm_db_get_pkgcache(db
); j
; j
= alpm_list_next(j
)) {
515 dump_pkg_sync(alpm_list_getdata(j
), alpm_db_get_name(db
), config
->op_s_info
);
523 static int sync_list(alpm_list_t
*syncs
, alpm_list_t
*targets
)
525 alpm_list_t
*i
, *j
, *ls
= NULL
;
526 pmdb_t
*db_local
= alpm_option_get_localdb();
529 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
530 const char *repo
= alpm_list_getdata(i
);
533 for(j
= syncs
; j
; j
= alpm_list_next(j
)) {
534 pmdb_t
*d
= alpm_list_getdata(j
);
536 if(strcmp(repo
, alpm_db_get_name(d
)) == 0) {
543 pm_fprintf(stderr
, PM_LOG_ERROR
,
544 _("repository \"%s\" was not found.\n"),repo
);
549 ls
= alpm_list_add(ls
, db
);
555 for(i
= ls
; i
; i
= alpm_list_next(i
)) {
556 pmdb_t
*db
= alpm_list_getdata(i
);
558 for(j
= alpm_db_get_pkgcache(db
); j
; j
= alpm_list_next(j
)) {
559 pmpkg_t
*pkg
= alpm_list_getdata(j
);
561 if (!config
->quiet
) {
562 printf("%s %s %s", alpm_db_get_name(db
), alpm_pkg_get_name(pkg
),
563 alpm_pkg_get_version(pkg
));
564 print_installed(db_local
, pkg
);
567 printf("%s\n", alpm_pkg_get_name(pkg
));
579 static alpm_list_t
*syncfirst(void) {
580 alpm_list_t
*i
, *res
= NULL
;
582 for(i
= config
->syncfirst
; i
; i
= alpm_list_next(i
)) {
583 char *pkgname
= alpm_list_getdata(i
);
584 pmpkg_t
*pkg
= alpm_db_get_pkg(alpm_option_get_localdb(), pkgname
);
589 if(alpm_sync_newversion(pkg
, alpm_option_get_syncdbs())) {
590 res
= alpm_list_add(res
, strdup(pkgname
));
597 static pmdb_t
*get_db(const char *dbname
)
600 for(i
= alpm_option_get_syncdbs(); i
; i
= i
->next
) {
601 pmdb_t
*db
= i
->data
;
602 if(strcmp(alpm_db_get_name(db
), dbname
) == 0) {
609 static int process_pkg(pmpkg_t
*pkg
)
611 int ret
= alpm_add_pkg(pkg
);
614 if(pm_errno
== PM_ERR_TRANS_DUP_TARGET
615 || pm_errno
== PM_ERR_PKG_IGNORED
) {
616 /* just skip duplicate or ignored targets */
617 pm_printf(PM_LOG_WARNING
, _("skipping target: %s\n"), alpm_pkg_get_name(pkg
));
620 pm_fprintf(stderr
, PM_LOG_ERROR
, "'%s': %s\n", alpm_pkg_get_name(pkg
),
621 alpm_strerrorlast());
628 static int process_group(alpm_list_t
*dbs
, char *group
)
632 alpm_list_t
*pkgs
= alpm_find_grp_pkgs(dbs
, group
);
633 int count
= alpm_list_count(pkgs
);
636 pm_fprintf(stderr
, PM_LOG_ERROR
, _("target not found: %s\n"), group
);
640 printf(_(":: There are %d members in group %s:\n"), count
,
642 select_display(pkgs
);
643 char *array
= malloc(count
);
644 multiselect_question(array
, count
);
646 for(i
= pkgs
; i
; i
= alpm_list_next(i
)) {
649 pmpkg_t
*pkg
= alpm_list_getdata(i
);
651 if(process_pkg(pkg
) == 1) {
657 alpm_list_free(pkgs
);
662 static int process_targname(alpm_list_t
*dblist
, char *targname
)
664 pmpkg_t
*pkg
= alpm_find_dbs_satisfier(dblist
, targname
);
666 /* #FS23342 - skip ignored packages when user says no */
667 if(pm_errno
== PM_ERR_PKG_IGNORED
) {
668 pm_printf(PM_LOG_WARNING
, _("skipping target: %s\n"), targname
);
674 return(process_pkg(pkg
));
676 /* fallback on group */
677 return(process_group(dblist
, targname
));
680 static int process_target(char *target
)
682 /* process targets */
683 char *targstring
= strdup(target
);
684 char *targname
= strchr(targstring
, '/');
687 alpm_list_t
*dblist
= NULL
;
697 pm_fprintf(stderr
, PM_LOG_ERROR
, _("database not found: %s\n"),
702 dblist
= alpm_list_add(dblist
, db
);
703 ret
= process_targname(dblist
, targname
);
704 alpm_list_free(dblist
);
706 targname
= targstring
;
707 dblist
= alpm_option_get_syncdbs();
708 ret
= process_targname(dblist
, targname
);
715 static int sync_trans(alpm_list_t
*targets
)
718 alpm_list_t
*data
= NULL
;
719 alpm_list_t
*packages
= NULL
;
722 /* Step 1: create a new transaction... */
723 if(trans_init(config
->flags
) == -1) {
727 /* process targets */
728 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
729 char *targ
= alpm_list_getdata(i
);
730 if(process_target(targ
) == 1) {
736 if(config
->op_s_upgrade
) {
737 printf(_(":: Starting full system upgrade...\n"));
738 alpm_logaction("starting full system upgrade\n");
739 if(alpm_sync_sysupgrade(config
->op_s_upgrade
>= 2) == -1) {
740 pm_fprintf(stderr
, PM_LOG_ERROR
, "%s\n", alpm_strerrorlast());
746 /* Step 2: "compute" the transaction based on targets and flags */
747 if(alpm_trans_prepare(&data
) == -1) {
748 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to prepare transaction (%s)\n"),
749 alpm_strerrorlast());
752 case PM_ERR_PKG_INVALID_ARCH
:
753 for(i
= data
; i
; i
= alpm_list_next(i
)) {
754 char *pkg
= alpm_list_getdata(i
);
755 printf(_(":: package %s does not have a valid architecture\n"), pkg
);
758 case PM_ERR_UNSATISFIED_DEPS
:
759 for(i
= data
; i
; i
= alpm_list_next(i
)) {
760 pmdepmissing_t
*miss
= alpm_list_getdata(i
);
761 pmdepend_t
*dep
= alpm_miss_get_dep(miss
);
762 char *depstring
= alpm_dep_compute_string(dep
);
763 printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss
),
768 case PM_ERR_CONFLICTING_DEPS
:
769 for(i
= data
; i
; i
= alpm_list_next(i
)) {
770 pmconflict_t
*conflict
= alpm_list_getdata(i
);
771 const char *package1
= alpm_conflict_get_package1(conflict
);
772 const char *package2
= alpm_conflict_get_package2(conflict
);
773 const char *reason
= alpm_conflict_get_reason(conflict
);
774 /* only print reason if it contains new information */
775 if(strcmp(package1
, reason
) == 0 || strcmp(package2
, reason
) == 0) {
776 printf(_(":: %s and %s are in conflict\n"), package1
, package2
);
778 printf(_(":: %s and %s are in conflict (%s)\n"), package1
, package2
, reason
);
789 packages
= alpm_trans_get_add();
790 if(packages
== NULL
) {
791 /* nothing to do: just exit without complaining */
792 printf(_(" there is nothing to do\n"));
796 /* Step 3: actually perform the operation */
798 print_packages(packages
);
802 display_targets(alpm_trans_get_remove(), 0);
803 display_targets(alpm_trans_get_add(), 1);
807 if(config
->op_s_downloadonly
) {
808 confirm
= yesno(_("Proceed with download?"));
810 confirm
= yesno(_("Proceed with installation?"));
816 if(alpm_trans_commit(&data
) == -1) {
817 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to commit transaction (%s)\n"),
818 alpm_strerrorlast());
821 case PM_ERR_FILE_CONFLICTS
:
822 for(i
= data
; i
; i
= alpm_list_next(i
)) {
823 pmfileconflict_t
*conflict
= alpm_list_getdata(i
);
824 switch(alpm_fileconflict_get_type(conflict
)) {
825 case PM_FILECONFLICT_TARGET
:
826 printf(_("%s exists in both '%s' and '%s'\n"),
827 alpm_fileconflict_get_file(conflict
),
828 alpm_fileconflict_get_target(conflict
),
829 alpm_fileconflict_get_ctarget(conflict
));
831 case PM_FILECONFLICT_FILESYSTEM
:
832 printf(_("%s: %s exists in filesystem\n"),
833 alpm_fileconflict_get_target(conflict
),
834 alpm_fileconflict_get_file(conflict
));
839 case PM_ERR_PKG_INVALID
:
840 case PM_ERR_DLT_INVALID
:
841 for(i
= data
; i
; i
= alpm_list_next(i
)) {
842 char *filename
= alpm_list_getdata(i
);
843 printf(_("%s is invalid or corrupted\n"), filename
);
850 printf(_("Errors occurred, no packages were upgraded.\n"));
855 /* Step 4: release transaction resources */
860 if(trans_release() == -1) {
867 int pacman_sync(alpm_list_t
*targets
)
869 alpm_list_t
*sync_dbs
= NULL
;
871 /* clean the cache */
872 if(config
->op_s_clean
) {
875 if(trans_init(0) == -1) {
879 ret
+= sync_cleancache(config
->op_s_clean
);
881 ret
+= sync_cleandb_all();
883 if(trans_release() == -1) {
890 /* ensure we have at least one valid sync db set up */
891 sync_dbs
= alpm_option_get_syncdbs();
892 if(sync_dbs
== NULL
|| alpm_list_count(sync_dbs
) == 0) {
893 pm_printf(PM_LOG_ERROR
, _("no usable package repositories configured.\n"));
897 if(config
->op_s_sync
) {
898 /* grab a fresh package list */
899 printf(_(":: Synchronizing package databases...\n"));
900 alpm_logaction("synchronizing package lists\n");
901 if(!sync_synctree(config
->op_s_sync
, sync_dbs
)) {
906 /* search for a package */
907 if(config
->op_s_search
) {
908 return(sync_search(sync_dbs
, targets
));
911 /* look for groups */
913 return(sync_group(config
->group
, sync_dbs
, targets
));
916 /* get package info */
917 if(config
->op_s_info
) {
918 return(sync_info(sync_dbs
, targets
));
921 /* get a listing of files in sync DBs */
922 if(config
->op_q_list
) {
923 return(sync_list(sync_dbs
, targets
));
926 if(targets
== NULL
) {
927 if(config
->op_s_upgrade
) {
929 } else if(config
->op_s_sync
) {
932 /* don't proceed here unless we have an operation that doesn't require a
934 pm_printf(PM_LOG_ERROR
, _("no targets specified (use -h for help)\n"));
939 alpm_list_t
*targs
= alpm_list_strdup(targets
);
940 if(!(config
->flags
& PM_TRANS_FLAG_DOWNLOADONLY
) && !config
->print
) {
941 /* check for newer versions of packages to be upgraded first */
942 alpm_list_t
*packages
= syncfirst();
944 /* Do not ask user if all the -S targets are SyncFirst packages, see FS#15810 */
945 alpm_list_t
*tmp
= NULL
;
946 if(config
->op_s_upgrade
|| (tmp
= alpm_list_diff(targets
, packages
, (alpm_list_fn_cmp
)strcmp
))) {
948 printf(_(":: The following packages should be upgraded first :\n"));
949 list_display(" ", packages
);
950 if(yesno(_(":: Do you want to cancel the current operation\n"
951 ":: and upgrade these packages now?"))) {
955 config
->op_s_upgrade
= 0;
961 pm_printf(PM_LOG_DEBUG
, "skipping SyncFirst dialog\n");
967 int ret
= sync_trans(targs
);
973 /* vim: set ts=2 sw=2 noet: */