diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-12-25 07:59:28 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-12-25 07:59:28 +0000 |
commit | 959f0bca04be8a58bdf0533793dd17514251db27 (patch) | |
tree | 4f66a553b12529c123b90393884eab4df7b54e25 /libsylph | |
parent | 608ad31f3e7ca6270cac78ea2022467e0dc257a4 (diff) |
fixed crash when .sylpheed_mark is not writable.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1457 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/procmsg.c | 41 | ||||
-rw-r--r-- | libsylph/utils.c | 19 |
2 files changed, 50 insertions, 10 deletions
diff --git a/libsylph/procmsg.c b/libsylph/procmsg.c index 03f31da5..872eb1b4 100644 --- a/libsylph/procmsg.c +++ b/libsylph/procmsg.c @@ -23,6 +23,7 @@ #include <glib/gi18n.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include "utils.h" #include "procmsg.h" @@ -789,7 +790,8 @@ static void procmsg_write_mark_file(FolderItem *item, GHashTable *mark_table) { FILE *fp; - fp = procmsg_open_mark_file(item, DATA_WRITE); + if ((fp = procmsg_open_mark_file(item, DATA_WRITE)) == NULL) + return; g_hash_table_foreach(mark_table, write_mark_func, fp); fclose(fp); } @@ -804,8 +806,16 @@ FILE *procmsg_open_data_file(const gchar *file, guint version, if (mode == DATA_WRITE) { if ((fp = g_fopen(file, "wb")) == NULL) { - FILE_OP_ERROR(file, "fopen"); - return NULL; + if (errno == EACCES) { + change_file_mode_rw(NULL, file); + if ((fp = g_fopen(file, "wb")) == NULL) { + FILE_OP_ERROR(file, "fopen"); + return NULL; + } + } else { + FILE_OP_ERROR(file, "fopen"); + return NULL; + } } if (change_file_mode_rw(fp, file) < 0) FILE_OP_ERROR(file, "chmod"); @@ -815,9 +825,16 @@ FILE *procmsg_open_data_file(const gchar *file, guint version, } /* check version */ - if ((fp = g_fopen(file, "rb")) == NULL) - debug_print("Mark/Cache file '%s' not found\n", file); - else { + if ((fp = g_fopen(file, "rb")) == NULL) { + if (errno == EACCES) { + change_file_mode_rw(NULL, file); + if ((fp = g_fopen(file, "rb")) == NULL) { + FILE_OP_ERROR(file, "fopen"); + } + } else { + debug_print("Mark/Cache file '%s' not found\n", file); + } + } else { if (buf && buf_size > 0) setvbuf(fp, buf, _IOFBF, buf_size); if (fread(&data_ver, sizeof(data_ver), 1, fp) != 1 || @@ -835,8 +852,16 @@ FILE *procmsg_open_data_file(const gchar *file, guint version, if (fp) { /* reopen with append mode */ fclose(fp); - if ((fp = g_fopen(file, "ab")) == NULL) - FILE_OP_ERROR(file, "fopen"); + if ((fp = g_fopen(file, "ab")) == NULL) { + if (errno == EACCES) { + change_file_mode_rw(NULL, file); + if ((fp = g_fopen(file, "ab")) == NULL) { + FILE_OP_ERROR(file, "fopen"); + } + } else { + FILE_OP_ERROR(file, "fopen"); + } + } } else { /* open with overwrite mode if mark file doesn't exist or version is different */ diff --git a/libsylph/utils.c b/libsylph/utils.c index bd104e6e..428b5c84 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -3152,10 +3152,25 @@ gchar *generate_mime_boundary(const gchar *prefix) gint change_file_mode_rw(FILE *fp, const gchar *file) { +#ifdef G_OS_WIN32 + DWORD attr; + BOOL retval; + + attr = GetFileAttributes(file); + retval = SetFileAttributes + (file, attr & ~(FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN)); + if (retval) + return 0; + else + return -1; +#else #if HAVE_FCHMOD - return fchmod(fileno(fp), S_IRUSR|S_IWUSR); + if (fp) + return fchmod(fileno(fp), S_IRUSR|S_IWUSR); + else #else - return g_chmod(file, S_IRUSR|S_IWUSR); + return g_chmod(file, S_IRUSR|S_IWUSR); +#endif #endif } |