mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-09 04:57:59 -05:00
reworked lock handling (patch from VMiklos <vmiklos@frugalware.org>)
This commit is contained in:
parent
18986b1805
commit
831ff882ae
@ -50,8 +50,6 @@
|
||||
#include "handle.h"
|
||||
#include "alpm.h"
|
||||
|
||||
#define PM_LOCK "/tmp/pacman.lck"
|
||||
|
||||
/* Globals */
|
||||
pmhandle_t *handle = NULL;
|
||||
enum __pmerrno_t pm_errno;
|
||||
@ -76,15 +74,6 @@ int alpm_initialize(char *root)
|
||||
RET_ERR(PM_ERR_MEMORY, -1);
|
||||
}
|
||||
|
||||
/* lock db */
|
||||
if(handle->access == PM_ACCESS_RW) {
|
||||
handle->lckfd = _alpm_lckmk(PM_LOCK);
|
||||
if(handle->lckfd == -1) {
|
||||
FREE(handle);
|
||||
RET_ERR(PM_ERR_HANDLE_LOCK, -1);
|
||||
}
|
||||
}
|
||||
|
||||
STRNCPY(str, (root) ? root : PM_ROOT, PATH_MAX);
|
||||
/* add a trailing '/' if there isn't one */
|
||||
if(str[strlen(str)-1] != '/') {
|
||||
@ -105,16 +94,14 @@ int alpm_release()
|
||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||
|
||||
/* unlock db */
|
||||
if(handle->access == PM_ACCESS_RW) {
|
||||
if(handle->lckfd != -1) {
|
||||
close(handle->lckfd);
|
||||
handle->lckfd = -1;
|
||||
}
|
||||
if(_alpm_lckrm(PM_LOCK)) {
|
||||
if(_alpm_lckrm(PM_LOCK) == -1) {
|
||||
_alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK);
|
||||
alpm_logaction("warning: could not remove lock file %s", PM_LOCK);
|
||||
}
|
||||
}
|
||||
|
||||
/* close local database */
|
||||
if(handle->db_local) {
|
||||
@ -664,6 +651,12 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event
|
||||
* perform sanity checks on type and flags:
|
||||
* for instance, we can't set UPGRADE and FRESHEN at the same time */
|
||||
|
||||
/* lock db */
|
||||
handle->lckfd = _alpm_lckmk(PM_LOCK);
|
||||
if(handle->lckfd == -1) {
|
||||
RET_ERR(PM_ERR_HANDLE_LOCK, -1);
|
||||
}
|
||||
|
||||
handle->trans = trans_new();
|
||||
if(handle->trans == NULL) {
|
||||
RET_ERR(PM_ERR_MEMORY, -1);
|
||||
@ -765,6 +758,16 @@ int alpm_trans_release()
|
||||
|
||||
FREETRANS(handle->trans);
|
||||
|
||||
/* unlock db */
|
||||
if(handle->lckfd != -1) {
|
||||
close(handle->lckfd);
|
||||
handle->lckfd = -1;
|
||||
}
|
||||
if(_alpm_lckrm(PM_LOCK) == -1) {
|
||||
_alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK);
|
||||
alpm_logaction("warning: could not remove lock file %s", PM_LOCK);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
/** @} */
|
||||
|
@ -225,7 +225,10 @@ int _alpm_lckmk(char *file)
|
||||
*/
|
||||
int _alpm_lckrm(char *file)
|
||||
{
|
||||
return(unlink(file) == -1);
|
||||
if(unlink(file) == -1 && errno != ENOENT) {
|
||||
return(-1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int _alpm_unpack(char *archive, const char *prefix, const char *fn)
|
||||
|
Loading…
Reference in New Issue
Block a user