1
0
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:
Dan McGee 2011-06-24 04:11:38 -05:00
parent 7b8f8f69f1
commit 4f8ae2bab6
2 changed files with 24 additions and 25 deletions

View File

@ -113,26 +113,22 @@ valid:
* \a force is true, the update will only be performed if the remote * \a force is true, the update will only be performed if the remote
* database was modified since the last update. * database was modified since the last update.
* *
* A transaction is necessary for this operation, in order to obtain a * This operation requires a database lock, and will return an applicable error
* database lock. During this transaction the front-end will be informed * if the lock could not be obtained.
* of the download progress of the database via the download callback.
* *
* Example: * Example:
* @code * @code
* alpm_list_t *syncs = alpm_option_get_syncdbs(); * 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)) {
* for(i = syncs; i; i = alpm_list_next(i)) { * pmdb_t *db = alpm_list_getdata(i);
* pmdb_t *db = alpm_list_getdata(i); * result = alpm_db_update(0, db);
* result = alpm_db_update(0, db);
* alpm_trans_release();
* *
* if(result < 0) { * if(result < 0) {
* printf("Unable to update database: %s\n", alpm_strerrorlast()); * printf("Unable to update database: %s\n", alpm_strerrorlast());
* } else if(result == 1) { * } else if(result == 1) {
* printf("Database already up to date\n"); * printf("Database already up to date\n");
* } else { * } else {
* printf("Database updated\n"); * printf("Database updated\n");
* }
* } * }
* } * }
* @endcode * @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 != handle->db_local, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
ASSERT(db->servers != NULL, RET_ERR(handle, PM_ERR_SERVER_NONE, -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); syncpath = get_sync_dir(handle);
if(!syncpath) { if(!syncpath) {
return -1; return -1;
} }
/* make sure we have a sane umask */
oldmask = umask(0022);
check_sig = _alpm_db_get_sigverify_level(db); 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) { for(i = db->servers; i; i = i->next) {
const char *server = i->data; const char *server = i->data;
char *fileurl; char *fileurl;
@ -232,6 +234,10 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
cleanup: 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); free(syncpath);
umask(oldmask); umask(oldmask);
return ret; return ret;

View File

@ -283,10 +283,6 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_list_t *i; alpm_list_t *i;
int success = 0, ret; int success = 0, ret;
if(trans_init(0) == -1) {
return 0;
}
for(i = syncs; i; i = alpm_list_next(i)) { for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(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 /* 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 * fail later with unresolved deps, but that should be rare, and would be
* expected * expected