summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/trans.c
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-06-24 20:55:32 +0200
committerDave Reisner <d@falconindy.com>2011-06-24 20:55:32 +0200
commit2d32a9a3a348d25d6d0f3d12752399bf7fdf6570 (patch)
treebb330206ea0caa95c9d337a6c5b4b99b6034e756 /lib/libalpm/trans.c
parent8581694ceb63f4ed2854206b38574599c3d9df28 (diff)
parente06586ceb49a0dc7e59996ae3a1483337d2ada05 (diff)
downloadpacman-2d32a9a3a348d25d6d0f3d12752399bf7fdf6570.tar.gz
pacman-2d32a9a3a348d25d6d0f3d12752399bf7fdf6570.tar.xz
Merge branch 'master' of git://projects.archlinux.org/pacman
* 'master' of git://projects.archlinux.org/pacman: pactree: carry a list of databases for dep resolution makepkg: Remove a lone quotation mark makepkg: remove the cleancache option Don't require a transaction for sync DB updates Move locking functions to handle Add a 'valid' flag to the database object Move database 'version' check to registration time Do database signature checking at load time
Diffstat (limited to 'lib/libalpm/trans.c')
-rw-r--r--lib/libalpm/trans.c72
1 files changed, 10 insertions, 62 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index f0744937..507ea027 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -30,7 +30,6 @@
#include <sys/types.h>
#include <errno.h>
#include <limits.h>
-#include <fcntl.h>
/* libalpm */
#include "trans.h"
@@ -48,69 +47,28 @@
* @{
*/
-/* Create a lock file */
-static int make_lock(pmhandle_t *handle)
-{
- int fd;
- char *dir, *ptr;
-
- ASSERT(handle->lockfile != NULL, return -1);
-
- /* create the dir of the lockfile first */
- dir = strdup(handle->lockfile);
- ptr = strrchr(dir, '/');
- if(ptr) {
- *ptr = '\0';
- }
- if(_alpm_makepath(dir)) {
- FREE(dir);
- return -1;
- }
- FREE(dir);
-
- do {
- fd = open(handle->lockfile, O_WRONLY | O_CREAT | O_EXCL, 0000);
- } while(fd == -1 && errno == EINTR);
- if(fd > 0) {
- FILE *f = fdopen(fd, "w");
- fprintf(f, "%ld\n", (long)getpid());
- fflush(f);
- fsync(fd);
- handle->lckstream = f;
- return 0;
- }
- return -1;
-}
-
-/* Remove a lock file */
-static int remove_lock(pmhandle_t *handle)
-{
- if(handle->lckstream != NULL) {
- fclose(handle->lckstream);
- handle->lckstream = NULL;
- }
- if(unlink(handle->lockfile) == -1 && errno != ENOENT) {
- return -1;
- }
- return 0;
-}
-
/** Initialize the transaction. */
int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{
pmtrans_t *trans;
- const int required_db_version = 2;
- int db_version;
+ alpm_list_t *i;
/* Sanity checks */
CHECK_HANDLE(handle, return -1);
ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
+ for(i = handle->dbs_sync; i; i = i->next) {
+ const pmdb_t *db = i->data;
+ if(!(db->status & DB_STATUS_VALID)) {
+ RET_ERR(handle, PM_ERR_DB_INVALID, -1);
+ }
+ }
+
/* lock db */
if(!(flags & PM_TRANS_FLAG_NOLOCK)) {
- if(make_lock(handle)) {
+ if(_alpm_handle_lock(handle)) {
RET_ERR(handle, PM_ERR_HANDLE_LOCK, -1);
}
}
@@ -122,16 +80,6 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
trans->cb_progress = progress;
trans->state = STATE_INITIALIZED;
- /* check database version */
- db_version = _alpm_db_version(handle->db_local);
- if(db_version < required_db_version) {
- _alpm_log(handle, PM_LOG_ERROR,
- _("%s database version is too old\n"), handle->db_local->treename);
- remove_lock(handle);
- _alpm_trans_free(trans);
- RET_ERR(handle, PM_ERR_DB_VERSION, -1);
- }
-
handle->trans = trans;
return 0;
@@ -282,7 +230,7 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle)
/* unlock db */
if(!nolock_flag) {
- if(remove_lock(handle)) {
+ if(_alpm_handle_unlock(handle)) {
_alpm_log(handle, PM_LOG_WARNING, _("could not remove lock file %s\n"),
alpm_option_get_lockfile(handle));
alpm_logaction(handle, "warning: could not remove lock file %s\n",