diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-05 00:36:54 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-05 00:36:54 +0800 |
commit | b92cd47ad5105869b66b2166e2dafecbf8d29c93 (patch) | |
tree | 4dbb4d18f49594b603155abd4696e1dc286f99d1 /camel/providers | |
parent | 8a9862a5504e3987af99b9a444ca141736051c4d (diff) | |
download | gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar.gz gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar.bz2 gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar.lz gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar.xz gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.tar.zst gsoc2013-evolution-b92cd47ad5105869b66b2166e2dafecbf8d29c93.zip |
finshed implementation (_delete_messages): implemented.
1999-08-04 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/MH/camel-mh-folder.c (_delete):
finshed implementation
(_delete_messages): implemented.
svn path=/trunk/; revision=1076
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/MH/camel-mh-folder.c | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c index 206636578b..8027be95b6 100644 --- a/camel/providers/MH/camel-mh-folder.c +++ b/camel/providers/MH/camel-mh-folder.c @@ -21,14 +21,17 @@ * USA */ -#include "camel-mh-folder.h" -#include "camel-mh-store.h" -#include "gstring-util.h" -#include <sys/stat.h> +#include <sys/stat.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> - +#include <dirent.h> +#include <stdio.h> +#include <errno.h> +#include "camel-mh-folder.h" +#include "camel-mh-store.h" +#include "gstring-util.h" +#include "camel-log.h" static CamelFolderClass *parent_class=NULL; @@ -42,6 +45,8 @@ static void _set_name(CamelFolder *folder, const gchar *name); static void _init_with_store (CamelFolder *folder, CamelStore *parent_store); static gboolean _exists (CamelFolder *folder); static gboolean _create(CamelFolder *folder); +static gboolean _delete (CamelFolder *folder, gboolean recurse); +static gboolean _delete_messages (CamelFolder *folder); static void camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) @@ -55,6 +60,8 @@ camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) camel_folder_class->init_with_store = _init_with_store; camel_folder_class->set_name = _set_name; camel_folder_class->exists = _exists; + camel_folder_class->delete = _delete; + camel_folder_class->delete_messages = _delete_messages; } @@ -159,7 +166,7 @@ _exists (CamelFolder *folder) static gboolean -_create(CamelFolder *folder) +_create (CamelFolder *folder) { CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); const gchar *directory_path; @@ -188,19 +195,93 @@ _delete (CamelFolder *folder, gboolean recurse) CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); const gchar *directory_path; - gint rmdir_error; - + gint rmdir_error = 0; + g_assert(folder); /* call default implementation */ parent_class->delete (folder, recurse); - + /* the default implementation will care about deleting + messages first and recursing the operation if + necessary */ + directory_path = mh_folder->directory_path; if (!directory_path) return FALSE; if (!camel_folder_exists (folder)) return TRUE; - + /* physically delete the directory */ + CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete removing directory %s\n", directory_path); rmdir_error = rmdir (directory_path); + if (rmdir_error == -1) { + CAMEL_LOG_FULL_WARNING ("CamelMhFolder::delete Error when removing directory %s\n", directory_path); + CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); + } + + return (rmdir_error != -1); +} + + +static gboolean +_delete_messages (CamelFolder *folder) +{ + + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + const gchar *directory_path; + struct stat stat_buf; + gint stat_error = 0; + GList *file_list; + gchar *entry_name; + struct dirent *dir_entry; + gint unlink_error = 0; + DIR *dir_handle; + + g_assert(folder); + + /* call default implementation */ + parent_class->delete_messages (folder); + + directory_path = mh_folder->directory_path; + if (!directory_path) return FALSE; + + if (!camel_folder_exists (folder)) return TRUE; + + dir_handle = opendir (directory_path); + + /* read first entry in the directory */ + dir_entry = readdir (dir_handle); + while ((stat_error != -1) && (unlink_error != -1) && (dir_entry != NULL)) { + + /* get the name of the next entry in the dir */ + entry_name = dir_entry->d_name; + stat_error = stat (mh_folder->directory_path, &stat_buf); + + /* is it a regular file ? */ + if ((stat_error != -1) && S_ISREG(stat_buf.st_mode)) { + /* yes, delete it */ + CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete_messages removing file %s\n", entry_name); + unlink_error = unlink(entry_name); + + if (unlink_error == -1) { + CAMEL_LOG_FULL_WARNING ("CamelMhFolder::delete_messages Error when deleting file %s\n", entry_name); + CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); + } + } + /* read next entry */ + dir_entry = readdir (dir_handle); + } + + closedir (dir_handle); + + return ((stat_error != -1) && (unlink_error != -1)); } + + + + + + + + + |