aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-block-file.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-04-19 11:15:54 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-04-19 11:15:54 +0800
commit04ccbdd8e80cac98e26ecdf781101fedf748ac15 (patch)
tree706bd55d11891e3bb39e360a31a27233bb71f831 /camel/camel-block-file.c
parentd68227cb50fd2dba42dbba0c843220f5dfc434f2 (diff)
downloadgsoc2013-evolution-04ccbdd8e80cac98e26ecdf781101fedf748ac15.tar.gz
gsoc2013-evolution-04ccbdd8e80cac98e26ecdf781101fedf748ac15.tar.zst
gsoc2013-evolution-04ccbdd8e80cac98e26ecdf781101fedf748ac15.zip
** for #40989
2003-04-17 Not Zed <NotZed@Ximian.com> ** for #40989 * camel-text-index.c (text_index_delete): delete the block file/key file directly, not just its files. * providers/local/camel-local-folder.c (local_delete): implement, just delete the index file if it exists. camel-store-delete-folder will delete other data (maybe it all should be done here). * camel-block-file.c (camel_key_file_finalise): keep lock around decrementing key file use count. (camel_key_file_delete): new function to delete the key file (& close it off). (key_file_use): if we've been deleted, always fail. (camel_block_file_finalise): only close the file if its a valid fd. (block_file_use): if we've been deleted, always fail. (camel_block_file_delete): delete the block file & close. (struct _CamelBlockFilePrivate): fix the !ENABLE_THREADS case to still compile this. svn path=/trunk/; revision=20894
Diffstat (limited to 'camel/camel-block-file.c')
-rw-r--r--camel/camel-block-file.c77
1 files changed, 70 insertions, 7 deletions
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index 3ba97ba556..9f0101c892 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -43,8 +43,6 @@
#define d(x) /*(printf("%s(%d):%s: ", __FILE__, __LINE__, __PRETTY_FUNCTION__),(x))*/
-#ifdef ENABLE_THREADS
-
/* Locks must be obtained in the order defined */
struct _CamelBlockFilePrivate {
@@ -54,11 +52,15 @@ struct _CamelBlockFilePrivate {
struct _CamelBlockFile *base;
+#ifdef ENABLE_THREADS
pthread_mutex_t root_lock; /* for modifying the root block */
pthread_mutex_t cache_lock; /* for refcounting, flag manip, cache manip */
pthread_mutex_t io_lock; /* for all io ops */
+#endif
+ unsigned int deleted:1;
};
+#ifdef ENABLE_THREADS
#define CAMEL_BLOCK_FILE_LOCK(kf, lock) (pthread_mutex_lock(&(kf)->priv->lock))
#define CAMEL_BLOCK_FILE_TRYLOCK(kf, lock) (pthread_mutex_trylock(&(kf)->priv->lock))
#define CAMEL_BLOCK_FILE_UNLOCK(kf, lock) (pthread_mutex_unlock(&(kf)->priv->lock))
@@ -237,7 +239,8 @@ camel_block_file_finalise(CamelBlockFile *bs)
if (bs->root_block)
camel_block_file_unref_block(bs, bs->root_block);
g_free(bs->path);
- close(bs->fd);
+ if (bs->fd != -1)
+ close(bs->fd);
#ifdef ENABLE_THREADS
pthread_mutex_destroy(&p->io_lock);
@@ -286,7 +289,11 @@ block_file_use(CamelBlockFile *bs)
if (bs->fd != -1)
return 0;
- else
+ else if (p->deleted) {
+ CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
+ errno = ENOENT;
+ return -1;
+ } else
d(printf("Turning block file online: %s\n", bs->path));
if ((bs->fd = open(bs->path, bs->flags, 0600)) == -1) {
@@ -438,6 +445,31 @@ camel_block_file_rename(CamelBlockFile *bs, const char *path)
return ret;
}
+int
+camel_block_file_delete(CamelBlockFile *bs)
+{
+ int ret;
+ struct _CamelBlockFilePrivate *p = bs->priv;
+
+ CAMEL_BLOCK_FILE_LOCK(bs, io_lock);
+
+ if (bs->fd != -1) {
+ LOCK(block_file_lock);
+ block_file_count--;
+ UNLOCK(block_file_lock);
+ close(bs->fd);
+ bs->fd = -1;
+ }
+
+ p->deleted = TRUE;
+ ret = unlink(bs->path);
+
+ CAMEL_BLOCK_FILE_UNLOCK(bs, io_lock);
+
+ return ret;
+
+}
+
/**
* camel_block_file_new_block:
* @bs:
@@ -779,10 +811,10 @@ struct _CamelKeyFilePrivate {
struct _CamelKeyFilePrivate *prev;
struct _CamelKeyFile *base;
-
#ifdef ENABLE_THREADS
pthread_mutex_t lock;
#endif
+ unsigned int deleted:1;
};
#ifdef ENABLE_THREADS
@@ -833,12 +865,14 @@ camel_key_file_finalise(CamelKeyFile *bs)
LOCK(key_file_lock);
e_dlist_remove((EDListNode *)p);
- UNLOCK(key_file_lock);
if (bs-> fp) {
key_file_count--;
fclose(bs->fp);
}
+
+ UNLOCK(key_file_lock);
+
g_free(bs->path);
#ifdef ENABLE_THREADS
@@ -890,7 +924,11 @@ key_file_use(CamelKeyFile *bs)
if (bs->fp != NULL)
return 0;
- else
+ else if (p->deleted) {
+ CAMEL_KEY_FILE_UNLOCK(bs, lock);
+ errno = ENOENT;
+ return -1;
+ } else
d(printf("Turning key file online: '%s'\n", bs->path));
if ((bs->flags & O_ACCMODE) == O_RDONLY)
@@ -1033,6 +1071,31 @@ camel_key_file_rename(CamelKeyFile *kf, const char *path)
return ret;
}
+int
+camel_key_file_delete(CamelKeyFile *kf)
+{
+ int ret;
+ struct _CamelKeyFilePrivate *p = kf->priv;
+
+ CAMEL_KEY_FILE_LOCK(kf, lock);
+
+ if (kf->fp) {
+ LOCK(key_file_lock);
+ key_file_count--;
+ UNLOCK(key_file_lock);
+ fclose(kf->fp);
+ kf->fp = NULL;
+ }
+
+ p->deleted = TRUE;
+ ret = unlink(kf->path);
+
+ CAMEL_KEY_FILE_UNLOCK(kf, lock);
+
+ return ret;
+
+}
+
/**
* camel_key_file_write:
* @kf: