aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/nntp/camel-nntp-newsrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/nntp/camel-nntp-newsrc.c')
-rw-r--r--camel/providers/nntp/camel-nntp-newsrc.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c
index 81594d3dcd..9510fe5bfa 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.c
+++ b/camel/providers/nntp/camel-nntp-newsrc.c
@@ -26,6 +26,8 @@
#include <string.h>
#include <stdlib.h>
#include <glib.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "camel-nntp-newsrc.h"
typedef struct {
@@ -440,17 +442,33 @@ camel_nntp_newsrc_read_for_server (const char *server)
{
FILE *fp;
char buf[BUFFER_LENGTH];
- CamelNNTPNewsrc *newsrc = g_new0(CamelNNTPNewsrc, 1);
+ char *filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
+ CamelNNTPNewsrc *newsrc;
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ int fd;
+
+ g_warning ("~/.newsrc-%s not present. creating empty file\n", server);
+
+ if ((fd = open (filename, O_CREAT, O_TRUNC, O_WRONLY, 0777)) < 0) {
+ g_warning ("unable to create ~/.newsrc-%s file\n", server);
+ g_free (filename);
+ return NULL;
+ }
+ close (fd);
- newsrc->filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
+ if ((fp = fopen(filename, "r")) == NULL) {
+ g_warning ("unable to open ~/.newsrc-%s file on second try.\n", server);
+ g_free (filename);
+ return NULL;
+ }
+ }
+
+ newsrc = g_new0(CamelNNTPNewsrc, 1);
+ newsrc->filename = filename;
newsrc->groups = g_hash_table_new (g_str_hash, g_str_equal);
newsrc->subscribed_groups = g_hash_table_new (g_str_hash, g_str_equal);
- if ((fp = fopen(newsrc->filename, "r")) == NULL) {
- g_free (newsrc->filename);
- g_free (newsrc);
- return NULL;
- }
while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) {
/* we silently ignore (and lose!) lines longer than 20 * 1500 chars.