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/>.
26 #include <sys/types.h>
29 #include <stdint.h> /* int64_t */
33 #include <archive_entry.h>
38 #include "alpm_list.h"
49 /** Add a package to the transaction. */
50 int SYMEXPORT
alpm_add_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
)
52 const char *pkgname
, *pkgver
;
57 CHECK_HANDLE(handle
, return -1);
58 ASSERT(pkg
!= NULL
, RET_ERR(handle
, ALPM_ERR_WRONG_ARGS
, -1));
59 ASSERT(handle
== pkg
->handle
, RET_ERR(handle
, ALPM_ERR_WRONG_ARGS
, -1));
60 trans
= handle
->trans
;
61 ASSERT(trans
!= NULL
, RET_ERR(handle
, ALPM_ERR_TRANS_NULL
, -1));
62 ASSERT(trans
->state
== STATE_INITIALIZED
,
63 RET_ERR(handle
, ALPM_ERR_TRANS_NOT_INITIALIZED
, -1));
66 pkgver
= pkg
->version
;
68 _alpm_log(handle
, ALPM_LOG_DEBUG
, "adding package '%s'\n", pkgname
);
70 if(_alpm_pkg_find(trans
->add
, pkgname
)) {
71 RET_ERR(handle
, ALPM_ERR_TRANS_DUP_TARGET
, -1);
74 local
= _alpm_db_get_pkgfromcache(handle
->db_local
, pkgname
);
76 const char *localpkgname
= local
->name
;
77 const char *localpkgver
= local
->version
;
78 int cmp
= _alpm_pkg_compare_versions(pkg
, local
);
81 if(trans
->flags
& ALPM_TRANS_FLAG_NEEDED
) {
82 /* with the NEEDED flag, packages up to date are not reinstalled */
83 _alpm_log(handle
, ALPM_LOG_WARNING
, _("%s-%s is up to date -- skipping\n"),
84 localpkgname
, localpkgver
);
86 } else if(!(trans
->flags
& ALPM_TRANS_FLAG_DOWNLOADONLY
)) {
87 _alpm_log(handle
, ALPM_LOG_WARNING
, _("%s-%s is up to date -- reinstalling\n"),
88 localpkgname
, localpkgver
);
91 /* local version is newer */
92 _alpm_log(handle
, ALPM_LOG_WARNING
, _("downgrading package %s (%s => %s)\n"),
93 localpkgname
, localpkgver
, pkgver
);
97 /* add the package to the transaction */
98 pkg
->reason
= ALPM_PKG_REASON_EXPLICIT
;
99 _alpm_log(handle
, ALPM_LOG_DEBUG
, "adding package %s-%s to the transaction add list\n",
101 trans
->add
= alpm_list_add(trans
->add
, pkg
);
106 static int perform_extraction(alpm_handle_t
*handle
, struct archive
*archive
,
107 struct archive_entry
*entry
, const char *filename
, const char *origname
)
110 const int archive_flags
= ARCHIVE_EXTRACT_OWNER
|
111 ARCHIVE_EXTRACT_PERM
|
112 ARCHIVE_EXTRACT_TIME
;
114 archive_entry_set_pathname(entry
, filename
);
116 ret
= archive_read_extract(archive
, entry
, archive_flags
);
117 if(ret
== ARCHIVE_WARN
&& archive_errno(archive
) != ENOSPC
) {
118 /* operation succeeded but a "non-critical" error was encountered */
119 _alpm_log(handle
, ALPM_LOG_WARNING
, _("warning given when extracting %s (%s)\n"),
120 origname
, archive_error_string(archive
));
121 } else if(ret
!= ARCHIVE_OK
) {
122 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not extract %s (%s)\n"),
123 origname
, archive_error_string(archive
));
124 alpm_logaction(handle
, "error: could not extract %s (%s)\n",
125 origname
, archive_error_string(archive
));
131 static int try_rename(alpm_handle_t
*handle
, const char *src
, const char *dest
)
133 if(rename(src
, dest
)) {
134 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not rename %s to %s (%s)\n"),
135 src
, dest
, strerror(errno
));
136 alpm_logaction(handle
, "error: could not rename %s to %s (%s)\n",
137 src
, dest
, strerror(errno
));
143 static int extract_single_file(alpm_handle_t
*handle
, struct archive
*archive
,
144 struct archive_entry
*entry
, alpm_pkg_t
*newpkg
, alpm_pkg_t
*oldpkg
)
146 const char *entryname
;
148 char filename
[PATH_MAX
]; /* the actual file we're extracting */
149 int needbackup
= 0, notouch
= 0;
150 const char *hash_orig
= NULL
;
151 char *entryname_orig
= NULL
;
154 entryname
= archive_entry_pathname(entry
);
155 entrymode
= archive_entry_mode(entry
);
157 if(strcmp(entryname
, ".INSTALL") == 0) {
158 /* the install script goes inside the db */
159 snprintf(filename
, PATH_MAX
, "%s%s-%s/install",
160 _alpm_db_path(handle
->db_local
), newpkg
->name
, newpkg
->version
);
161 archive_entry_set_perm(entry
, 0644);
162 } else if(strcmp(entryname
, ".CHANGELOG") == 0) {
163 /* the changelog goes inside the db */
164 snprintf(filename
, PATH_MAX
, "%s%s-%s/changelog",
165 _alpm_db_path(handle
->db_local
), newpkg
->name
, newpkg
->version
);
166 archive_entry_set_perm(entry
, 0644);
167 } else if(*entryname
== '.') {
168 /* for now, ignore all files starting with '.' that haven't
169 * already been handled (for future possibilities) */
170 _alpm_log(handle
, ALPM_LOG_DEBUG
, "skipping extraction of '%s'\n", entryname
);
171 archive_read_data_skip(archive
);
174 /* build the new entryname relative to handle->root */
175 snprintf(filename
, PATH_MAX
, "%s%s", handle
->root
, entryname
);
178 /* if a file is in NoExtract then we never extract it */
179 if(alpm_list_find(handle
->noextract
, entryname
, _alpm_fnmatch
)) {
180 _alpm_log(handle
, ALPM_LOG_DEBUG
, "%s is in NoExtract, skipping extraction\n",
182 alpm_logaction(handle
, "note: %s is in NoExtract, skipping extraction\n",
184 archive_read_data_skip(archive
);
188 /* Check for file existence. This is one of the more crucial parts
189 * to get 'right'. Here are the possibilities, with the filesystem
190 * on the left and the package on the top:
191 * (F=file, N=node, S=symlink, D=dir)
193 * non-existent | 1 | 2 | 3
198 * 1,2,3- extract, no magic necessary. lstat (_alpm_lstat) will fail here.
199 * 4,5,6,7,8- conflict checks should have caught this. either overwrite
200 * or backup the file.
201 * 9- follow the symlink, hopefully it is a directory, check it.
202 * 10- file replacing directory- don't allow it.
203 * 11- don't extract symlink- a dir exists here. we don't want links to
205 * 12- skip extraction, dir already exists.
208 /* do both a lstat and a stat, so we can see what symlinks point to */
209 struct stat lsbuf
, sbuf
;
210 if(_alpm_lstat(filename
, &lsbuf
) != 0 || stat(filename
, &sbuf
) != 0) {
211 /* cases 1,2,3: couldn't stat an existing file, skip all backup checks */
213 if(S_ISDIR(lsbuf
.st_mode
)) {
214 if(S_ISDIR(entrymode
)) {
215 /* case 12: existing dir, ignore it */
216 if(lsbuf
.st_mode
!= entrymode
) {
217 /* if filesystem perms are different than pkg perms, warn user */
219 _alpm_log(handle
, ALPM_LOG_WARNING
, _("directory permissions differ on %s\n"
220 "filesystem: %o package: %o\n"), entryname
, lsbuf
.st_mode
& mask
,
222 alpm_logaction(handle
, "warning: directory permissions differ on %s\n"
223 "filesystem: %o package: %o\n", entryname
, lsbuf
.st_mode
& mask
,
226 _alpm_log(handle
, ALPM_LOG_DEBUG
, "extract: skipping dir extraction of %s\n",
228 archive_read_data_skip(archive
);
231 /* case 10/11: trying to overwrite dir with file/symlink, don't allow it */
232 _alpm_log(handle
, ALPM_LOG_ERROR
, _("extract: not overwriting dir with file %s\n"),
234 archive_read_data_skip(archive
);
237 } else if(S_ISLNK(lsbuf
.st_mode
) && S_ISDIR(entrymode
)) {
238 /* case 9: existing symlink, dir in package */
239 if(S_ISDIR(sbuf
.st_mode
)) {
240 /* the symlink on FS is to a directory, so we'll use it */
241 _alpm_log(handle
, ALPM_LOG_DEBUG
, "extract: skipping symlink overwrite of %s\n",
243 archive_read_data_skip(archive
);
246 /* this is BAD. symlink was not to a directory */
247 _alpm_log(handle
, ALPM_LOG_ERROR
, _("extract: symlink %s does not point to dir\n"),
249 archive_read_data_skip(archive
);
252 } else if(S_ISREG(lsbuf
.st_mode
) && S_ISDIR(entrymode
)) {
253 /* case 6: trying to overwrite file with dir */
254 _alpm_log(handle
, ALPM_LOG_DEBUG
, "extract: overwriting file with dir %s\n",
256 } else if(S_ISREG(entrymode
)) {
258 /* if file is in NoUpgrade, don't touch it */
259 if(alpm_list_find(handle
->noupgrade
, entryname
, _alpm_fnmatch
)) {
262 alpm_backup_t
*backup
;
263 /* go to the backup array and see if our conflict is there */
264 /* check newpkg first, so that adding backup files is retroactive */
265 backup
= _alpm_needbackup(entryname
, newpkg
);
267 /* if we force hash_orig to be non-NULL retroactive backup works */
272 /* check oldpkg for a backup entry, store the hash if available */
274 backup
= _alpm_needbackup(entryname
, oldpkg
);
276 hash_orig
= backup
->hash
;
282 /* else if(S_ISLNK(entrymode)) */
283 /* case 5,8: don't need to do anything special */
286 /* we need access to the original entryname later after calls to
287 * archive_entry_set_pathname(), so we need to dupe it and free() later */
288 STRDUP(entryname_orig
, entryname
, RET_ERR(handle
, ALPM_ERR_MEMORY
, -1));
292 char *hash_local
= NULL
, *hash_pkg
= NULL
;
295 len
= strlen(filename
) + 10;
296 MALLOC(checkfile
, len
,
297 errors
++; handle
->pm_errno
= ALPM_ERR_MEMORY
; goto needbackup_cleanup
);
298 snprintf(checkfile
, len
, "%s.paccheck", filename
);
300 if(perform_extraction(handle
, archive
, entry
, checkfile
, entryname_orig
)) {
302 goto needbackup_cleanup
;
305 hash_local
= alpm_compute_md5sum(filename
);
306 hash_pkg
= alpm_compute_md5sum(checkfile
);
308 /* update the md5 hash in newpkg's backup (it will be the new orginal) */
310 for(i
= alpm_pkg_get_backup(newpkg
); i
; i
= i
->next
) {
311 alpm_backup_t
*backup
= i
->data
;
313 if(!backup
->name
|| strcmp(backup
->name
, entryname_orig
) != 0) {
316 STRDUP(newhash
, hash_pkg
, RET_ERR(handle
, ALPM_ERR_MEMORY
, -1));
318 backup
->hash
= newhash
;
321 _alpm_log(handle
, ALPM_LOG_DEBUG
, "checking hashes for %s\n", entryname_orig
);
322 _alpm_log(handle
, ALPM_LOG_DEBUG
, "current: %s\n", hash_local
);
323 _alpm_log(handle
, ALPM_LOG_DEBUG
, "new: %s\n", hash_pkg
);
324 _alpm_log(handle
, ALPM_LOG_DEBUG
, "original: %s\n", hash_orig
);
327 if(hash_local
&& hash_pkg
&& strcmp(hash_local
, hash_pkg
) != 0) {
328 /* looks like we have a local file that has a different hash as the
329 * file in the package, move it to a .pacorig */
331 size_t newlen
= strlen(filename
) + 9;
332 MALLOC(newpath
, newlen
,
333 errors
++; handle
->pm_errno
= ALPM_ERR_MEMORY
; goto needbackup_cleanup
);
334 snprintf(newpath
, newlen
, "%s.pacorig", filename
);
336 /* move the existing file to the "pacorig" */
337 if(try_rename(handle
, filename
, newpath
)) {
341 /* rename the file we extracted to the real name */
342 if(try_rename(handle
, checkfile
, filename
)) {
345 _alpm_log(handle
, ALPM_LOG_WARNING
, _("%s saved as %s\n"), filename
, newpath
);
346 alpm_logaction(handle
, "warning: %s saved as %s\n", filename
, newpath
);
351 /* local file is identical to pkg one, so just remove pkg one */
354 } else if(hash_orig
) {
357 if(hash_local
&& strcmp(hash_orig
, hash_local
) == 0) {
358 /* installed file has NOT been changed by user */
359 if(hash_pkg
&& strcmp(hash_orig
, hash_pkg
) != 0) {
360 _alpm_log(handle
, ALPM_LOG_DEBUG
, "action: installing new file: %s\n",
363 if(try_rename(handle
, checkfile
, filename
)) {
367 /* no sense in installing the same file twice, install
368 * ONLY if the original and package hashes differ */
369 _alpm_log(handle
, ALPM_LOG_DEBUG
, "action: leaving existing file in place\n");
372 } else if(hash_pkg
&& strcmp(hash_orig
, hash_pkg
) == 0) {
373 /* originally installed file and new file are the same - this
374 * implies the case above failed - i.e. the file was changed by a
376 _alpm_log(handle
, ALPM_LOG_DEBUG
, "action: leaving existing file in place\n");
378 } else if(hash_local
&& hash_pkg
&& strcmp(hash_local
, hash_pkg
) == 0) {
379 /* this would be magical. The above two cases failed, but the
380 * user changes just so happened to make the new file exactly the
381 * same as the one in the package... skip it */
382 _alpm_log(handle
, ALPM_LOG_DEBUG
, "action: leaving existing file in place\n");
386 size_t newlen
= strlen(filename
) + 8;
387 _alpm_log(handle
, ALPM_LOG_DEBUG
, "action: keeping current file and installing"
388 " new one with .pacnew ending\n");
389 MALLOC(newpath
, newlen
,
390 errors
++; handle
->pm_errno
= ALPM_ERR_MEMORY
; goto needbackup_cleanup
);
391 snprintf(newpath
, newlen
, "%s.pacnew", filename
);
392 if(try_rename(handle
, checkfile
, newpath
)) {
395 _alpm_log(handle
, ALPM_LOG_WARNING
, _("%s installed as %s\n"),
397 alpm_logaction(handle
, "warning: %s installed as %s\n",
409 /* we didn't need a backup */
411 /* change the path to a .pacnew extension */
412 _alpm_log(handle
, ALPM_LOG_DEBUG
, "%s is in NoUpgrade -- skipping\n", filename
);
413 _alpm_log(handle
, ALPM_LOG_WARNING
, _("extracting %s as %s.pacnew\n"), filename
, filename
);
414 alpm_logaction(handle
, "warning: extracting %s as %s.pacnew\n", filename
, filename
);
415 strncat(filename
, ".pacnew", PATH_MAX
- strlen(filename
));
417 _alpm_log(handle
, ALPM_LOG_DEBUG
, "extracting %s\n", filename
);
420 if(handle
->trans
->flags
& ALPM_TRANS_FLAG_FORCE
) {
421 /* if FORCE was used, unlink() each file (whether it's there
422 * or not) before extracting. This prevents the old "Text file busy"
423 * error that crops up if forcing a glibc or pacman upgrade. */
427 if(perform_extraction(handle
, archive
, entry
, filename
, entryname_orig
)) {
429 free(entryname_orig
);
434 /* calculate an hash if this is in newpkg's backup */
436 for(i
= alpm_pkg_get_backup(newpkg
); i
; i
= i
->next
) {
437 alpm_backup_t
*backup
= i
->data
;
439 if(!backup
->name
|| strcmp(backup
->name
, entryname_orig
) != 0) {
442 _alpm_log(handle
, ALPM_LOG_DEBUG
, "appending backup entry for %s\n", entryname_orig
);
443 newhash
= alpm_compute_md5sum(filename
);
445 backup
->hash
= newhash
;
448 free(entryname_orig
);
452 static int commit_single_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*newpkg
,
453 size_t pkg_current
, size_t pkg_count
)
455 int i
, ret
= 0, errors
= 0;
457 alpm_pkg_t
*oldpkg
= NULL
;
458 alpm_db_t
*db
= handle
->db_local
;
459 alpm_trans_t
*trans
= handle
->trans
;
462 ASSERT(trans
!= NULL
, return -1);
464 /* see if this is an upgrade. if so, remove the old package first */
465 alpm_pkg_t
*local
= _alpm_db_get_pkgfromcache(db
, newpkg
->name
);
469 /* we'll need to save some record for backup checks later */
470 if(_alpm_pkg_dup(local
, &oldpkg
) == -1) {
475 /* copy over the install reason */
476 newpkg
->reason
= alpm_pkg_get_reason(local
);
478 EVENT(handle
, ALPM_EVENT_UPGRADE_START
, newpkg
, local
);
481 EVENT(handle
, ALPM_EVENT_ADD_START
, newpkg
, NULL
);
484 pkgfile
= newpkg
->origin_data
.file
;
486 _alpm_log(handle
, ALPM_LOG_DEBUG
, "%s package %s-%s\n",
487 is_upgrade
? "upgrading" : "adding", newpkg
->name
, newpkg
->version
);
488 /* pre_install/pre_upgrade scriptlet */
489 if(alpm_pkg_has_scriptlet(newpkg
) &&
490 !(trans
->flags
& ALPM_TRANS_FLAG_NOSCRIPTLET
)) {
491 const char *scriptlet_name
= is_upgrade
? "pre_upgrade" : "pre_install";
493 _alpm_runscriptlet(handle
, pkgfile
, scriptlet_name
,
494 newpkg
->version
, oldpkg
? oldpkg
->version
: NULL
, 1);
497 /* we override any pre-set reason if we have alldeps or allexplicit set */
498 if(trans
->flags
& ALPM_TRANS_FLAG_ALLDEPS
) {
499 newpkg
->reason
= ALPM_PKG_REASON_DEPEND
;
500 } else if(trans
->flags
& ALPM_TRANS_FLAG_ALLEXPLICIT
) {
501 newpkg
->reason
= ALPM_PKG_REASON_EXPLICIT
;
505 /* set up fake remove transaction */
506 if(_alpm_remove_single_package(handle
, oldpkg
, newpkg
, 0, 0) == -1) {
507 handle
->pm_errno
= ALPM_ERR_TRANS_ABORT
;
513 /* prepare directory for database entries so permission are correct after
514 changelog/install script installation (FS#12263) */
515 if(_alpm_local_db_prepare(db
, newpkg
)) {
516 alpm_logaction(handle
, "error: could not create database entry %s-%s\n",
517 newpkg
->name
, newpkg
->version
);
518 handle
->pm_errno
= ALPM_ERR_DB_WRITE
;
523 if(!(trans
->flags
& ALPM_TRANS_FLAG_DBONLY
)) {
524 struct archive
*archive
;
525 struct archive_entry
*entry
;
529 _alpm_log(handle
, ALPM_LOG_DEBUG
, "extracting files\n");
531 fd
= _alpm_open_archive(db
->handle
, pkgfile
, &buf
,
532 &archive
, ALPM_ERR_PKG_OPEN
);
538 /* save the cwd so we can restore it later */
539 OPEN(cwdfd
, ".", O_RDONLY
);
541 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not get current working directory\n"));
544 /* libarchive requires this for extracting hard links */
545 if(chdir(handle
->root
) != 0) {
546 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not change directory to %s (%s)\n"),
547 handle
->root
, strerror(errno
));
548 archive_read_finish(archive
);
554 /* call PROGRESS once with 0 percent, as we sort-of skip that here */
556 PROGRESS(handle
, ALPM_PROGRESS_UPGRADE_START
,
557 newpkg
->name
, 0, pkg_count
, pkg_current
);
559 PROGRESS(handle
, ALPM_PROGRESS_ADD_START
,
560 newpkg
->name
, 0, pkg_count
, pkg_current
);
563 for(i
= 0; archive_read_next_header(archive
, &entry
) == ARCHIVE_OK
; i
++) {
566 if(newpkg
->size
!= 0) {
567 /* Using compressed size for calculations here, as newpkg->isize is not
568 * exact when it comes to comparing to the ACTUAL uncompressed size
569 * (missing metadata sizes) */
570 int64_t pos
= archive_position_compressed(archive
);
571 percent
= (pos
* 100) / newpkg
->size
;
580 PROGRESS(handle
, ALPM_PROGRESS_UPGRADE_START
,
581 newpkg
->name
, percent
, pkg_count
, pkg_current
);
583 PROGRESS(handle
, ALPM_PROGRESS_ADD_START
,
584 newpkg
->name
, percent
, pkg_count
, pkg_current
);
587 /* extract the next file from the archive */
588 errors
+= extract_single_file(handle
, archive
, entry
, newpkg
, oldpkg
);
590 archive_read_finish(archive
);
593 /* restore the old cwd if we have it */
595 if(fchdir(cwdfd
) != 0) {
596 _alpm_log(handle
, ALPM_LOG_ERROR
,
597 _("could not restore working directory (%s)\n"), strerror(errno
));
605 _alpm_log(handle
, ALPM_LOG_ERROR
, _("problem occurred while upgrading %s\n"),
607 alpm_logaction(handle
, "error: problem occurred while upgrading %s\n",
610 _alpm_log(handle
, ALPM_LOG_ERROR
, _("problem occurred while installing %s\n"),
612 alpm_logaction(handle
, "error: problem occurred while installing %s\n",
618 /* make an install date (in UTC) */
619 newpkg
->installdate
= time(NULL
);
621 _alpm_log(handle
, ALPM_LOG_DEBUG
, "updating database\n");
622 _alpm_log(handle
, ALPM_LOG_DEBUG
, "adding database entry '%s'\n", newpkg
->name
);
624 if(_alpm_local_db_write(db
, newpkg
, INFRQ_ALL
)) {
625 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not update database entry %s-%s\n"),
626 newpkg
->name
, newpkg
->version
);
627 alpm_logaction(handle
, "error: could not update database entry %s-%s\n",
628 newpkg
->name
, newpkg
->version
);
629 handle
->pm_errno
= ALPM_ERR_DB_WRITE
;
634 if(_alpm_db_add_pkgincache(db
, newpkg
) == -1) {
635 _alpm_log(handle
, ALPM_LOG_ERROR
, _("could not add entry '%s' in cache\n"),
640 PROGRESS(handle
, ALPM_PROGRESS_UPGRADE_START
,
641 newpkg
->name
, 100, pkg_count
, pkg_current
);
643 PROGRESS(handle
, ALPM_PROGRESS_ADD_START
,
644 newpkg
->name
, 100, pkg_count
, pkg_current
);
647 /* run the post-install script if it exists */
648 if(alpm_pkg_has_scriptlet(newpkg
)
649 && !(trans
->flags
& ALPM_TRANS_FLAG_NOSCRIPTLET
)) {
650 char *scriptlet
= _alpm_local_db_pkgpath(db
, newpkg
, "install");
651 const char *scriptlet_name
= is_upgrade
? "post_upgrade" : "post_install";
653 _alpm_runscriptlet(handle
, scriptlet
, scriptlet_name
,
654 newpkg
->version
, oldpkg
? oldpkg
->version
: NULL
, 0);
659 EVENT(handle
, ALPM_EVENT_UPGRADE_DONE
, newpkg
, oldpkg
);
661 EVENT(handle
, ALPM_EVENT_ADD_DONE
, newpkg
, oldpkg
);
665 _alpm_pkg_free(oldpkg
);
669 int _alpm_upgrade_packages(alpm_handle_t
*handle
)
671 size_t pkg_count
, pkg_current
;
672 int skip_ldconfig
= 0, ret
= 0;
674 alpm_trans_t
*trans
= handle
->trans
;
676 if(trans
->add
== NULL
) {
680 pkg_count
= alpm_list_count(trans
->add
);
683 /* loop through our package list adding/upgrading one at a time */
684 for(targ
= trans
->add
; targ
; targ
= targ
->next
) {
685 alpm_pkg_t
*newpkg
= targ
->data
;
687 if(handle
->trans
->state
== STATE_INTERRUPTED
) {
691 if(commit_single_pkg(handle
, newpkg
, pkg_current
, pkg_count
)) {
692 /* something screwed up on the commit, abort the trans */
693 trans
->state
= STATE_INTERRUPTED
;
694 handle
->pm_errno
= ALPM_ERR_TRANS_ABORT
;
695 /* running ldconfig at this point could possibly screw system */
704 /* run ldconfig if it exists */
705 _alpm_ldconfig(handle
);
711 /* vim: set ts=2 sw=2 noet: */