talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit d510ecf8b865ce63b4074692eb8c80c0bfe7d704
parent 3c6940a955d0d3b11d940451f8cd1d81433eda20
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Tue, 16 Jun 2015 22:52:47 +0200

RSSyl: Got rid of opendir/readdir/closedir in favour of Glib functions.

Diffstat:
Msrc/plugins/rssyl/parse822.c | 32++++++++++++++------------------
Msrc/plugins/rssyl/rssyl.c | 34++++++++++++++++++++--------------
Msrc/plugins/rssyl/rssyl_update_comments.c | 31+++++++++++++++++--------------
3 files changed, 51 insertions(+), 46 deletions(-)

diff --git a/src/plugins/rssyl/parse822.c b/src/plugins/rssyl/parse822.c @@ -241,9 +241,9 @@ static void rssyl_flush_folder_func(gpointer data, gpointer user_data) static void rssyl_folder_read_existing_real(RFolderItem *ritem) { gchar *path = NULL, *fname = NULL; - DIR *dp; - struct dirent *d; - GStatBuf st; + GDir *dp; + const gchar *d; + GError *error; gint num; FeedItem *item = NULL; RFeedCtx *ctx; @@ -263,34 +263,30 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem) ritem->items = NULL; ritem->last_update = 0; - if( (dp = opendir(path)) == NULL ) { - FILE_OP_ERROR(path, "opendir"); + if( (dp = g_dir_open(path, 0, &error)) == NULL ) { + FILE_OP_ERROR(path, "g_dir_open"); + debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n", + path, error->code, error->message); g_free(path); return; } - while( (d = readdir(dp)) != NULL ) { + while( (d = g_dir_read_name(dp)) != NULL ) { if( claws_is_exiting() ) { - closedir(dp); + g_dir_close(dp); g_free(path); return; } - if( d->d_name[0] != '.' && (num = to_number(d->d_name)) > 0 ) { - fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d->d_name); - if( g_stat(fname, &st) < 0 ) { - debug_print("RSSyl: couldn't stat() file '%s', ignoring it\n", fname); - g_free(fname); - continue; - } - - if( !S_ISREG(st.st_mode)) { + if( d[0] != '.' && (num = to_number(d)) > 0 ) { + fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d); + if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR)) { debug_print("RSSyl: not a regular file: '%s', ignoring it\n", fname); g_free(fname); continue; } - debug_print("RSSyl: starting to parse '%s'\n", d->d_name); + debug_print("RSSyl: starting to parse '%s'\n", d); if( (item = rssyl_parse_folder_item_file(fname)) != NULL ) { /* Find latest timestamp */ ctx = (RFeedCtx *)item->data; @@ -303,7 +299,7 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem) } } - closedir(dp); + g_dir_close(dp); g_free(path); ritem->items = g_slist_reverse(ritem->items); diff --git a/src/plugins/rssyl/rssyl.c b/src/plugins/rssyl/rssyl.c @@ -203,8 +203,9 @@ static gchar *rssyl_get_new_msg_filename(FolderItem *dest) static void rssyl_get_last_num(Folder *folder, FolderItem *item) { gchar *path; - DIR *dp; - struct dirent *d; + const char *f; + GDir *dp; + GError *error; gint max = 0; gint num; @@ -214,21 +215,24 @@ static void rssyl_get_last_num(Folder *folder, FolderItem *item) path = folder_item_get_path(item); g_return_if_fail(path != NULL); - if( (dp = opendir(path)) == NULL ) { - FILE_OP_ERROR(item->path, "opendir"); + if( (dp = g_dir_open(path, 0, &error)) == NULL ) { + FILE_OP_ERROR(item->path, "g_dir_open"); + debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n", + path, error->code, error->message); g_free(path); return; } g_free(path); - while( (d = readdir(dp)) != NULL ) { - if( (num = to_number(d->d_name)) > 0 && dirent_is_regular_file(d) ) { + while( (f = g_dir_read_name(dp)) != NULL) { + if ((num = to_number(f)) > 0 && + g_file_test(f, G_FILE_TEST_IS_REGULAR)) { if( max < num ) max = num; } } - closedir(dp); + g_dir_close(dp); debug_print("Last number in dir %s = %d\n", item->path, max); item->last_num = max; @@ -650,8 +654,9 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item, MsgNumberList **list, gboolean *old_uids_valid) { gchar *path; - DIR *dp; - struct dirent *d; + GDir *dp; + const gchar *d; + GError *error; gint num, nummsgs = 0; g_return_val_if_fail(item != NULL, -1); @@ -663,22 +668,23 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item, path = folder_item_get_path(item); g_return_val_if_fail(path != NULL, -1); - if( (dp = opendir(path)) == NULL ) { + if( (dp = g_dir_open(path, 0, &error)) == NULL ) { FILE_OP_ERROR(item->path, "opendir"); + debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n", + path, error->code, error->message); g_free(path); return -1; } g_free(path); - while( (d = readdir(dp)) != NULL ) { - if( (num = to_number(d->d_name)) > 0 ) { + while( (d = g_dir_read_name(dp)) != NULL ) { + if( (num = to_number(d)) > 0 ) { *list = g_slist_prepend(*list, GINT_TO_POINTER(num)); nummsgs++; } } - - closedir(dp); + g_dir_close(dp); debug_print("RSSyl: get_num_list: returning %d\n", nummsgs); diff --git a/src/plugins/rssyl/rssyl_update_comments.c b/src/plugins/rssyl/rssyl_update_comments.c @@ -56,8 +56,9 @@ void rssyl_update_comments(RFolderItem *ritem) FolderItem *item = &ritem->item; FeedItem *fi = NULL; RFetchCtx *ctx = NULL; - DIR *dp; - struct dirent *d; + GDir *dp; + const gchar *d; + GError *error; gint num; gchar *path, *msg, *fname; MainWindow *mainwin = mainwindow_get_mainwindow(); @@ -72,30 +73,32 @@ void rssyl_update_comments(RFolderItem *ritem) debug_print("RSSyl: starting to parse comments, path is '%s'\n", path); - if( (dp = opendir(path)) == NULL ) { - FILE_OP_ERROR(item->path, "opendir"); + if( (dp = g_dir_open(path, 0, &error)) == NULL ) { + FILE_OP_ERROR(item->path, "g_dir_open"); + debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n", + path, error->code, error->message); + g_error_free(error); g_free(path); return; } ritem->fetching_comments = TRUE; - while( (d = readdir(dp)) != NULL ) { + while( (d = g_dir_read_name(dp)) != NULL ) { if (claws_is_exiting()) { - closedir(dp); + g_dir_close(dp); g_free(path); debug_print("RSSyl: bailing out, app is exiting\n"); return; } -#ifdef G_OS_WIN32 - if( (num = to_number(d->d_name)) > 0) { -#else - if( (num = to_number(d->d_name)) > 0 && d->d_type == DT_REG ) { -#endif - debug_print("RSSyl: starting to parse '%s'\n", d->d_name); + if( (num = to_number(d)) > 0) { + fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d); + if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR)) + continue; + + debug_print("RSSyl: starting to parse '%s'\n", d); - fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d->d_name); if( (fi = rssyl_parse_folder_item_file(fname)) != NULL ) { if( feed_item_get_comments_url(fi) && feed_item_get_id(fi) && (ritem->fetch_comments_max_age == -1 || @@ -135,7 +138,7 @@ void rssyl_update_comments(RFolderItem *ritem) } } - closedir(dp); + g_dir_close(dp); g_free(path); ritem->fetching_comments = FALSE;