aboutsummaryrefslogtreecommitdiffstats
path: root/libibex
diff options
context:
space:
mode:
author0 <NotZed@Ximian.com>2001-10-30 13:21:16 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-10-30 13:21:16 +0800
commit6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035 (patch)
tree35766282d9d70e849bf7e361badfb9d931900049 /libibex
parent613e004309c27c94abd4b7159f430796ae70228a (diff)
downloadgsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar.gz
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar.bz2
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar.lz
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar.xz
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.tar.zst
gsoc2013-evolution-6e4ce3ebfbe5d9f721e2d2d42e35d8e2b370f035.zip
If we can't open blocks, dont try to deref it. (ibex_move): Dont try to
2001-10-30 <NotZed@Ximian.com> * ibex_block.c (ibex_reset): If we can't open blocks, dont try to deref it. (ibex_move): Dont try to rename if we have no file to rename. Change all callers to ibex_use to call it inside the lock. Otherwise it could change while we're trying to use it ... (ibex_use): Dont lock ib here, always assume we have it locked already, and dont try to close it if we run across it in the list. svn path=/trunk/; revision=14430
Diffstat (limited to 'libibex')
-rw-r--r--libibex/ChangeLog5
-rw-r--r--libibex/ibex_block.c67
-rw-r--r--libibex/ibex_internal.h2
3 files changed, 44 insertions, 30 deletions
diff --git a/libibex/ChangeLog b/libibex/ChangeLog
index 15e7296eea..d1e4866a47 100644
--- a/libibex/ChangeLog
+++ b/libibex/ChangeLog
@@ -2,6 +2,11 @@
* ibex_block.c (ibex_reset): If we can't open blocks, dont try to
deref it.
+ (ibex_move): Dont try to rename if we have no file to rename.
+ Change all callers to ibex_use to call it inside the lock.
+ Otherwise it could change while we're trying to use it ...
+ (ibex_use): Dont lock ib here, always assume we have it locked
+ already, and dont try to close it if we run across it in the list.
2001-10-29 <NotZed@Ximian.com>
diff --git a/libibex/ibex_block.c b/libibex/ibex_block.c
index 74eb594ad6..d8dade7986 100644
--- a/libibex/ibex_block.c
+++ b/libibex/ibex_block.c
@@ -12,6 +12,10 @@
#include <errno.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
@@ -48,7 +52,6 @@ static void ibex_use(ibex *ib)
/* always lock list then ibex */
IBEX_LIST_LOCK(ib);
- IBEX_LOCK(ib);
if (ib->blocks == NULL) {
o(printf("Delayed opening ibex '%s', total = %d\n", ib->name, ibex_opened+1));
@@ -71,8 +74,6 @@ static void ibex_use(ibex *ib)
ibex_list_remove((struct _listnode *)ib);
ibex_list_addtail(&ibex_list, (struct _listnode *)ib);
- IBEX_UNLOCK(ib);
-
/* check env variable override for open threshold */
if (!ibex_open_init) {
char *limit;
@@ -92,18 +93,20 @@ static void ibex_use(ibex *ib)
wb = (ibex *)ibex_list.head;
wn = wb->next;
while (wn) {
- IBEX_LOCK(wb);
- if (wb->usecount == 0 && wb->blocks != NULL) {
- o(printf("Forcing close of obex '%s', total = %d\n", wb->name, ibex_opened-1));
- close_backend(wb);
+ if (wb != ib) {
+ IBEX_LOCK(wb);
+ if (wb->usecount == 0 && wb->blocks != NULL) {
+ o(printf("Forcing close of obex '%s', total = %d\n", wb->name, ibex_opened-1));
+ close_backend(wb);
+ IBEX_UNLOCK(wb);
+ /* optimise the next scan? */
+ /*ibex_list_remove((struct _listnode *)wb);
+ ibex_list_addtail(&ibex_list, (struct _listnode *)wb);*/
+ ibex_opened--;
+ break;
+ }
IBEX_UNLOCK(wb);
- /* optimise the next scan? */
- /*ibex_list_remove((struct _listnode *)wb);
- ibex_list_addtail(&ibex_list, (struct _listnode *)wb);*/
- ibex_opened--;
- break;
}
- IBEX_UNLOCK(wb);
wb = wn;
wn = wn->next;
}
@@ -114,12 +117,9 @@ static void ibex_use(ibex *ib)
static void ibex_unuse(ibex *ib)
{
- IBEX_LOCK(ib);
ib->usecount--;
- IBEX_UNLOCK(ib);
}
-
static signed char utf8_trans[] = {
'A', 'A', 'A', 'A', 'A', 'A', -1, 'C', 'E', 'E', 'E', 'E', 'I', 'I',
'I', 'I', -2, 'N', 'O', 'O', 'O', 'O', 'O', '*', 'O', 'U', 'U', 'U',
@@ -300,9 +300,10 @@ done:
g_free(word);
word = NULL;
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
+
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
printf("Error in indexing\n");
ret = -1;
@@ -319,9 +320,10 @@ done:
ret = 0;
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+ IBEX_UNLOCK(ib);
+
error:
for (i=0;i<wordlist->len;i++)
g_free(wordlist->pdata[i]);
@@ -388,9 +390,10 @@ int ibex_save (ibex *ib)
d(printf("syncing database\n"));
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
+
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
ibex_reset(ib);
printf("Error saving\n");
@@ -406,9 +409,10 @@ int ibex_save (ibex *ib)
ret = 0;
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+ IBEX_UNLOCK(ib);
+
return ret;
}
@@ -496,13 +500,16 @@ int ibex_close (ibex *ib)
int ibex_move(ibex *ib, const char *newname)
{
int ret = 0, error = 0;
+ struct stat st;
IBEX_LOCK(ib);
if (ib->blocks)
close_backend(ib);
- if (rename(ib->name, newname) == -1) {
+ if (stat(ib->name, &st) == -1 && errno == ENOENT) {
+ error = 0;
+ } else if (rename(ib->name, newname) == -1) {
g_warning("could not rename ibex file '%s' to '%s': '%s'", ib->name, newname, strerror(errno));
ret = -1;
error = errno;
@@ -531,9 +538,10 @@ void ibex_unindex (ibex *ib, char *name)
{
d(printf("trying to unindex '%s'\n", name));
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
+
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
printf("Error unindexing!\n");
ibex_reset(ib);
@@ -541,8 +549,9 @@ void ibex_unindex (ibex *ib, char *name)
ib->words->klass->unindex_name(ib->words, name);
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+
+ IBEX_UNLOCK(ib);
}
/**
@@ -564,8 +573,8 @@ GPtrArray *ibex_find (ibex *ib, char *word)
normal = alloca(len+1);
ibex_normalise_word(word, word+len, normal);
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
ibex_reset(ib);
@@ -574,8 +583,8 @@ GPtrArray *ibex_find (ibex *ib, char *word)
ret = ib->words->klass->find(ib->words, normal);
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+ IBEX_UNLOCK(ib);
return ret;
}
@@ -600,8 +609,8 @@ gboolean ibex_find_name (ibex *ib, char *name, char *word)
normal = alloca(len+1);
ibex_normalise_word(word, word+len, normal);
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
ibex_reset(ib);
@@ -610,8 +619,8 @@ gboolean ibex_find_name (ibex *ib, char *name, char *word)
ret = ib->words->klass->find_name(ib->words, name, normal);
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+ IBEX_UNLOCK(ib);
return ret;
}
@@ -629,8 +638,8 @@ gboolean ibex_contains_name(ibex *ib, char *name)
{
gboolean ret;
- ibex_use(ib);
IBEX_LOCK(ib);
+ ibex_use(ib);
if (ibex_block_cache_setjmp(ib->blocks) != 0) {
ibex_reset(ib);
@@ -639,8 +648,8 @@ gboolean ibex_contains_name(ibex *ib, char *name)
ret = ib->words->klass->contains_name(ib->words, name);
}
- IBEX_UNLOCK(ib);
ibex_unuse(ib);
+ IBEX_UNLOCK(ib);
return ret;
}
diff --git a/libibex/ibex_internal.h b/libibex/ibex_internal.h
index 9b8c4ce6b2..dfcb496594 100644
--- a/libibex/ibex_internal.h
+++ b/libibex/ibex_internal.h
@@ -19,6 +19,7 @@
#include "config.h"
+#include <e-util/e-msgport.h>
#include <glib.h>
#include "ibex.h"
@@ -38,7 +39,6 @@ struct ibex {
struct _IBEXWord *words;
int predone;
- /* sigh i hate glib's mutex stuff too */
#ifdef ENABLE_THREADS
GMutex *lock;
#endif