aboutsummaryrefslogtreecommitdiffstats
path: root/camel
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
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')
-rw-r--r--camel/ChangeLog24
-rw-r--r--camel/camel-block-file.c77
-rw-r--r--camel/camel-block-file.h2
-rw-r--r--camel/camel-text-index.c10
-rw-r--r--camel/providers/local/camel-local-folder.c12
5 files changed, 117 insertions, 8 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 9532578654..e35775d5ea 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -15,6 +15,30 @@
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.
+
+ ** for #41163
+
* camel-multipart-signed.c (parse_content): Dont assume adding 1
to line length will go to the next line. e.g. for dos lines that
end in \r\n. Fix for #41163.
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:
diff --git a/camel/camel-block-file.h b/camel/camel-block-file.h
index e78254e1ed..eec0ee26f9 100644
--- a/camel/camel-block-file.h
+++ b/camel/camel-block-file.h
@@ -99,6 +99,7 @@ CamelType camel_block_file_get_type(void);
CamelBlockFile *camel_block_file_new(const char *path, int flags, const char version[8], size_t block_size);
int camel_block_file_rename(CamelBlockFile *bs, const char *path);
+int camel_block_file_delete(CamelBlockFile *kf);
CamelBlock *camel_block_file_new_block(CamelBlockFile *bs);
int camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id);
@@ -134,6 +135,7 @@ CamelType camel_key_file_get_type(void);
CamelKeyFile * camel_key_file_new(const char *path, int flags, const char version[8]);
int camel_key_file_rename(CamelKeyFile *kf, const char *path);
+int camel_key_file_delete(CamelKeyFile *kf);
int camel_key_file_write(CamelKeyFile *kf, camel_block_t *parent, size_t len, camel_key_t *records);
int camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, size_t *len, camel_key_t **records);
diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c
index 710723168b..dfc85a1f55 100644
--- a/camel/camel-text-index.c
+++ b/camel/camel-text-index.c
@@ -531,7 +531,15 @@ fail:
static int
text_index_delete(CamelIndex *idx)
{
- return camel_text_index_remove(idx->path);
+ struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
+ int ret = 0;
+
+ if (camel_block_file_delete(p->blocks) == -1)
+ ret = -1;
+ if (camel_key_file_delete(p->links) == -1)
+ ret = -1;
+
+ return ret;
}
static int
diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c
index c93f8b18c7..ca49071d2e 100644
--- a/camel/providers/local/camel-local-folder.c
+++ b/camel/providers/local/camel-local-folder.c
@@ -79,6 +79,7 @@ static GPtrArray *local_search_by_expression(CamelFolder *folder, const char *ex
static GPtrArray *local_search_by_uids(CamelFolder *folder, const char *expression, GPtrArray *uids, CamelException *ex);
static void local_search_free(CamelFolder *folder, GPtrArray * result);
+static void local_delete(CamelFolder *folder);
static void local_rename(CamelFolder *folder, const char *newname);
static void local_finalize(CamelObject * object);
@@ -104,6 +105,7 @@ camel_local_folder_class_init(CamelLocalFolderClass * camel_local_folder_class)
camel_folder_class->search_by_uids = local_search_by_uids;
camel_folder_class->search_free = local_search_free;
+ camel_folder_class->delete = local_delete;
camel_folder_class->rename = local_rename;
camel_local_folder_class->lock = local_lock;
@@ -437,6 +439,16 @@ local_expunge(CamelFolder *folder, CamelException *ex)
}
static void
+local_delete(CamelFolder *folder)
+{
+ CamelLocalFolder *lf = (CamelLocalFolder *)folder;
+
+ camel_index_delete(lf->index);
+
+ parent_class->delete(folder);
+}
+
+static void
local_rename(CamelFolder *folder, const char *newname)
{
CamelLocalFolder *lf = (CamelLocalFolder *)folder;