diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | ChangeLog.ja | 11 | ||||
-rw-r--r-- | libsylph/procmsg.c | 41 | ||||
-rw-r--r-- | libsylph/utils.c | 19 |
4 files changed, 71 insertions, 10 deletions
@@ -1,5 +1,15 @@ 2006-12-25 + * libsylph/utils.c: change_file_mode_rw(): win32: use + SetFileAttributes() to change file attributes. + * libsylph/procmsg.c: + procmsg_write_mark_file(): check if procmsg_open_mark_file() really + succeeds (fixes crash when .sylpheed_mark is not writable). + procmsg_open_data_file(): remove read-only/hidden attributes + when data file is unable to open with EACCES. + +2006-12-25 + * libsylph/socket.c: added #include "utils.h" (fixes compilation failure with GLib 2.4). diff --git a/ChangeLog.ja b/ChangeLog.ja index c7faa043..d979af3a 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,5 +1,16 @@ 2006-12-25 + * libsylph/utils.c: change_file_mode_rw(): win32: ファイルの属性を + 変更するのに SetFileAttributes() を使用するようにした。 + * libsylph/procmsg.c: + procmsg_write_mark_file(): procmsg_open_mark_file() が本当に成功 + したかどうかをチェックするようにした(.sylpheed_mark が書き込み不可 + の場合クラッシュするのを修正)。 + procmsg_open_data_file(): データファイルが EACCES で開けない場合は + 読み取り専用/隠しファイル属性を除去するようにした。 + +2006-12-25 + * libsylph/socket.c: #include "utils.h" を追加(GLib 2.4 でコンパイルに 失敗するのを修正)。 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 } |