mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-12 04:15:06 -05:00
Don't require a transaction for sync DB updates
Instead, just do the required locking directly in the backend in calls to alpm_db_update(). Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
7b8f8f69f1
commit
4f8ae2bab6
@ -113,26 +113,22 @@ valid:
|
||||
* \a force is true, the update will only be performed if the remote
|
||||
* database was modified since the last update.
|
||||
*
|
||||
* A transaction is necessary for this operation, in order to obtain a
|
||||
* database lock. During this transaction the front-end will be informed
|
||||
* of the download progress of the database via the download callback.
|
||||
* This operation requires a database lock, and will return an applicable error
|
||||
* if the lock could not be obtained.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* alpm_list_t *syncs = alpm_option_get_syncdbs();
|
||||
* if(alpm_trans_init(0, NULL, NULL, NULL) == 0) {
|
||||
* for(i = syncs; i; i = alpm_list_next(i)) {
|
||||
* pmdb_t *db = alpm_list_getdata(i);
|
||||
* result = alpm_db_update(0, db);
|
||||
* alpm_trans_release();
|
||||
* for(i = syncs; i; i = alpm_list_next(i)) {
|
||||
* pmdb_t *db = alpm_list_getdata(i);
|
||||
* result = alpm_db_update(0, db);
|
||||
*
|
||||
* if(result < 0) {
|
||||
* printf("Unable to update database: %s\n", alpm_strerrorlast());
|
||||
* } else if(result == 1) {
|
||||
* printf("Database already up to date\n");
|
||||
* } else {
|
||||
* printf("Database updated\n");
|
||||
* }
|
||||
* if(result < 0) {
|
||||
* printf("Unable to update database: %s\n", alpm_strerrorlast());
|
||||
* } else if(result == 1) {
|
||||
* printf("Database already up to date\n");
|
||||
* } else {
|
||||
* printf("Database updated\n");
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
@ -162,15 +158,21 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
||||
ASSERT(db != handle->db_local, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
|
||||
ASSERT(db->servers != NULL, RET_ERR(handle, PM_ERR_SERVER_NONE, -1));
|
||||
|
||||
/* make sure we have a sane umask */
|
||||
oldmask = umask(0022);
|
||||
|
||||
syncpath = get_sync_dir(handle);
|
||||
if(!syncpath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* make sure we have a sane umask */
|
||||
oldmask = umask(0022);
|
||||
|
||||
check_sig = _alpm_db_get_sigverify_level(db);
|
||||
|
||||
/* attempt to grab a lock */
|
||||
if(_alpm_handle_lock(handle)) {
|
||||
RET_ERR(handle, PM_ERR_HANDLE_LOCK, -1);
|
||||
}
|
||||
|
||||
for(i = db->servers; i; i = i->next) {
|
||||
const char *server = i->data;
|
||||
char *fileurl;
|
||||
@ -232,6 +234,10 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
||||
|
||||
cleanup:
|
||||
|
||||
if(_alpm_handle_unlock(handle)) {
|
||||
_alpm_log(handle, PM_LOG_WARNING, _("could not remove lock file %s\n"),
|
||||
alpm_option_get_lockfile(handle));
|
||||
}
|
||||
free(syncpath);
|
||||
umask(oldmask);
|
||||
return ret;
|
||||
|
@ -283,10 +283,6 @@ static int sync_synctree(int level, alpm_list_t *syncs)
|
||||
alpm_list_t *i;
|
||||
int success = 0, ret;
|
||||
|
||||
if(trans_init(0) == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = syncs; i; i = alpm_list_next(i)) {
|
||||
pmdb_t *db = alpm_list_getdata(i);
|
||||
|
||||
@ -302,9 +298,6 @@ static int sync_synctree(int level, alpm_list_t *syncs)
|
||||
}
|
||||
}
|
||||
|
||||
if(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
|
||||
|
Loading…
Reference in New Issue
Block a user