sync with 0.8.1cvs19
authorPaul Mangan <paul@claws-mail.org>
Thu, 8 Aug 2002 05:56:32 +0000 (05:56 +0000)
committerPaul Mangan <paul@claws-mail.org>
Thu, 8 Aug 2002 05:56:32 +0000 (05:56 +0000)
13 files changed:
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/compose.c
src/defs.h
src/inc.c
src/main.c
src/mbox.c
src/mh.c
src/summaryview.c
src/utils.c
src/utils.h

index 84924e4ba5dc91d9e02d0991c05c8ebd160a5ca2..0e66f5fa18336a77b0ee2c447ce669f659b87b9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2002-08-08
+
+       * src/utils.[ch]: get_tmp_file(): new. Returns the directory for
+         temporary files in ~/.sylpheed/.
+       * src/main.c: create temporary directory in ~/.sylpheed/.
+       * src/compose.c
+         src/inc.c: create temporary files in ~/.sylpheed/, and modified
+         the file name.
+         compose_exec_ext_editor(): fixed a bug that failed to create the
+         temporary file if g_get_tmp_dir() returned directory other than
+         '/tmp'.
+
+2002-08-08
+
+       * src/utils.c: copy_file(): check if dest_bak != NULL when unlinking.
+
+2002-08-08
+
+       * src/utils.[ch]: canonicalize_file_replace(): fixed a bug that fails
+         to replace the file when the given file and temporary file are not
+         on the same filesystem.
+         copy_file(): added a flag whether to keep backup.
+         move_file(): added a flag whether to overwrite the destination file.
+
 2002-08-07
 
        * src/socket.[ch]: fixed the linking failure when IPv6 is enabled.
index 69a4967acacc2cde0f36223be3fb16c840722fc5..830f256130c327d271a7c8d265193d13595344a8 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-08 [paul]      0.8.1claws36
+
+       * sync with 0.8.1cvs19
+               see ChangeLog 2002-08-08
+
 2002-08-07 [christoph] 0.8.1claws35
 
        * src/utils.c
index 02c3b2b5331c97b956b3a4b8309b7d12151c8606..77b57da848a42a3e1f081ec5dd710704863c7b12 100644 (file)
@@ -1,3 +1,27 @@
+2002-08-08
+
+       * src/utils.[ch]: get_tmp_file(): ¿·µ¬¡£ ~/.sylpheed/ Ãæ¤Î¥Æ¥ó¥Ý¥é¥ê
+         ¥Õ¥¡¥¤¥ëÍѤΥǥ£¥ì¥¯¥È¥ê¤òÊÖ¤¹¡£
+       * src/main.c: ~/.sylpheed/ Ãæ¤Ë¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¡£
+       * src/compose.c
+         src/inc.c: ~/.sylpheed/ Ãæ¤Ë¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤òºî¤ë¤è¤¦¤Ë¤·¡¢
+         ¥Õ¥¡¥¤¥ë̾¤ò½¤Àµ¡£
+         compose_exec_ext_editor(): g_get_tmp_dir() ¤¬ '/tmp' °Ê³°¤òÊÖ¤·¤¿
+         ¤È¤­¤Ë¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ÎºîÀ®¤Ë¼ºÇÔ¤¹¤ë¥Ð¥°¤ò½¤Àµ¡£
+
+2002-08-08
+
+       * src/utils.c: copy_file(): unlink ¤¹¤ë¤È¤­¤Ë dest_bak != NULL ¤«
+         ¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¡£
+
+2002-08-08
+
+       * src/utils.[ch]: canonicalize_file_replace(): Í¿¤¨¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤È
+         °ì»þ¥Õ¥¡¥¤¥ë¤¬Æ±¤¸¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¾å¤Ë¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¥Õ¥¡¥¤¥ë¤Î
+         ÃÖ¤­´¹¤¨¤Ë¼ºÇÔ¤¹¤ë¥Ð¥°¤ò½¤Àµ¡£
+         copy_file(): ¥Ð¥Ã¥¯¥¢¥Ã¥×¤òÊÝ»ý¤¹¤ë¤«¤É¤¦¤«¤Î¥Õ¥é¥°¤òÄɲá£
+         move_file(): °ÜÆ°Àè¥Õ¥¡¥¤¥ë¤ò¾å½ñ¤­¤¹¤ë¤«¤É¤¦¤«¤Î¥Õ¥é¥°¤òÄɲá£
+
 2002-08-07
 
        * src/socket.[ch]: IPv6 ¤¬Í­¸ú¤Ê¾ì¹ç¤Ë¥ê¥ó¥¯¤Ë¼ºÇÔ¤¹¤ë¤Î¤ò½¤Àµ¡£
index 1110c858332e234e0ac870fca04ce5420b256281..4f735644a445d37e95d4843f17f6649f6e8054d8 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws35
+EXTRA_VERSION=claws36
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 675d213c16491befe6cc5b56f928abcea898c312..7728c636294f8f70ad6a77dcd199cc356e48793c 100644 (file)
@@ -5479,20 +5479,22 @@ static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
 static void compose_exec_ext_editor(Compose *compose)
 {
-       gchar tmp[64];
+       gchar *tmp;
        pid_t pid;
        gint pipe_fds[2];
 
-       g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
-                  g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
+       tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
+                             G_DIR_SEPARATOR, (gint)compose);
 
        if (pipe(pipe_fds) < 0) {
                perror("pipe");
+               g_free(tmp);
                return;
        }
 
        if ((pid = fork()) < 0) {
                perror("fork");
+               g_free(tmp);
                return;
        }
 
@@ -5537,6 +5539,8 @@ static void compose_exec_ext_editor(Compose *compose)
                close(pipe_fds[1]);
                _exit(0);
        }
+
+       g_free(tmp);
 }
 
 static gint compose_exec_ext_editor_real(const gchar *file)
@@ -6080,7 +6084,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        lock = TRUE;
 
-       tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
+       tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
                              G_DIR_SEPARATOR, (gint)compose);
 
        if (compose_write_to_file(compose, tmp, TRUE) < 0) {
index 56d0fc8b107f830bc44c7f57ce43164a1ffc7fbe..8a6006b6652ee6991dc7ca89aaf6e55513097579 100644 (file)
@@ -57,6 +57,7 @@
 #define RENDERER_RC            "rendererrc"
 #define COMMAND_HISTORY                "command_history"
 #define TEMPLATE_DIR           "templates"
+#define TMP_DIR                        "tmp"
 #define NEWSGROUP_LIST         ".newsgroup_list"
 #define ADDRESS_BOOK           "addressbook.xml"
 #define MANUAL_HTML_INDEX      "sylpheed.html"
index b5b1c8296eba4b80251befc827c7dd2b2647fb2d..3323fde1910bed51b7e93656b7fea0f7ad966695 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1164,8 +1164,8 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
        if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
                return -1;
 
-       g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
-                  get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
+       g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox.%08x",
+                  get_tmp_dir(), G_DIR_SEPARATOR, (gint)mbox);
 
        if (copy_mbox(mbox, tmp_mbox) < 0) {
                unlock_mbox(mbox, lockfd, LOCK_FLOCK);
index ebd242a3d850d5ff2afab0baee35e5d93c669d8f..ac5e7f83bba3bb7c2e7e210dcf83b7995734f6a7 100644 (file)
@@ -215,6 +215,7 @@ int main(int argc, char *argv[])
        MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
+       MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
        MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
 
        if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
index db2931783da43ff130a67ce4f3ae1680351bc6bd..4120b6279ac1554f81c5baab18e5fe3fcfd7a84f 100644 (file)
@@ -368,7 +368,7 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type)
 
 gint copy_mbox(const gchar *src, const gchar *dest)
 {
-       return copy_file(src, dest);
+       return copy_file(src, dest, TRUE);
 }
 
 void empty_mbox(const gchar *mbox)
index 2c4a7659eedf93ca02dccbec6ca8df70bff43b27..c304fe3f232381507c7c53244a3f83789192e013 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -415,7 +415,7 @@ gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
        g_return_val_if_fail(destfile != NULL, -1);
 
        if (link(file, destfile) < 0) {
-               if (copy_file(file, destfile) < 0) {
+               if (copy_file(file, destfile, TRUE) < 0) {
                        g_warning(_("can't copy message %s to %s\n"),
                                  file, destfile);
                        g_free(destfile);
@@ -468,7 +468,7 @@ static gint mh_do_move(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
 
        srcfile = procmsg_get_message_file(msginfo);
 
-       if (move_file(srcfile, destfile) < 0) {
+       if (move_file(srcfile, destfile, FALSE) < 0) {
                g_free(srcfile);
                g_free(destfile);
                return -1;
@@ -565,7 +565,7 @@ static gint mh_do_move_msgs_with_dest(Folder *folder, FolderItem *dest,
                destfile = mh_get_new_msg_filename(dest);
                if(!destfile) return -1;
 
-               if (move_file(srcfile, destfile) < 0) {
+               if (move_file(srcfile, destfile, FALSE) < 0) {
                        g_free(srcfile);
                        g_free(destfile);
                        break;
@@ -633,8 +633,8 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                g_free(srcfile);
                return -1;
        }
-       
-       if (copy_file(srcfile, destfile) < 0) {
+
+       if (copy_file(srcfile, destfile, TRUE) < 0) {
                FILE_OP_ERROR(srcfile, "copy");
                g_free(srcfile);
                g_free(destfile);
@@ -731,7 +731,7 @@ gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                if (!destfile) break;
                srcfile = procmsg_get_message_file(msginfo);
 
-               if (copy_file(srcfile, destfile) < 0) {
+               if (copy_file(srcfile, destfile, TRUE) < 0) {
                        FILE_OP_ERROR(srcfile, "copy");
                        g_free(srcfile);
                        g_free(destfile);
index adf9eb5db0ae101f74108000dc7422915360b88d..ca3100a7c63ffb3e1a69e161d431e1ea3721ce32 100644 (file)
@@ -3126,7 +3126,7 @@ void summary_save_as(SummaryView *summaryview)
        }
 
        src = procmsg_get_message_file(msginfo);
-       if (copy_file(src, dest) < 0) {
+       if (copy_file(src, dest, TRUE) < 0) {
                alertpanel_error(_("Can't save the file `%s'."),
                                 g_basename(dest));
        }
index ba50629d03039fbdc583dd6b2fd5eb6b10b949ae..335ba219f540a11afe68e9e440b198239469b0ab 100644 (file)
@@ -1457,12 +1457,23 @@ gchar *get_header_cache_dir(void)
        return header_dir;
 }
 
+gchar *get_tmp_dir(void)
+{
+       static gchar *tmp_dir = NULL;
+
+       if (!tmp_dir)
+               tmp_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                     TMP_DIR, NULL);
+
+       return tmp_dir;
+}
+
 gchar *get_tmp_file(void)
 {
        static gchar *tmp_file = NULL;
 
        if (!tmp_file)
-               tmp_file = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+               tmp_file = g_strconcat(get_tmp_dir(), G_DIR_SEPARATOR_S,
                                       "tmpfile", NULL);
 
        return tmp_file;
@@ -1974,7 +1985,7 @@ gint copy_file(const gchar *src, const gchar *dest)
 }
 #endif
 
-gint copy_file(const gchar *src, const gchar *dest)
+gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
 {
        FILE *src_fp, *dest_fp;
        gint n_read;
@@ -2049,14 +2060,17 @@ gint copy_file(const gchar *src, const gchar *dest)
                return -1;
        }
 
+       if (keep_backup == FALSE && dest_bak)
+               unlink(dest_bak);
+
        g_free(dest_bak);
 
        return 0;
 }
 
-gint move_file(const gchar *src, const gchar *dest)
+gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
 {
-       if (is_file_exist(dest)) {
+       if (overwrite == FALSE && is_file_exist(dest)) {
                g_warning(_("move_file(): file %s already exists."), dest);
                return -1;
        }
@@ -2068,7 +2082,7 @@ gint move_file(const gchar *src, const gchar *dest)
                return -1;
        }
 
-       if (copy_file(src, dest) < 0) return -1;
+       if (copy_file(src, dest, FALSE) < 0) return -1;
 
        unlink(src);
 
@@ -2078,15 +2092,30 @@ gint move_file(const gchar *src, const gchar *dest)
 /* convert line endings into CRLF. If the last line doesn't end with
  * linebreak, add it.
  */
-gint canonicalize_file(FILE *src_fp, FILE *dest_fp)
+gint canonicalize_file(const gchar *src, const gchar *dest)
 {
+       FILE *src_fp, *dest_fp;
        gchar buf[BUFFSIZE];
        gint len;
        gboolean err = FALSE;
        gboolean last_linebreak = FALSE;
 
-       rewind(src_fp);
-       rewind(dest_fp);
+       if ((src_fp = fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "fopen");
+               return -1;
+       }
+
+       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "fopen");
+               fclose(src_fp);
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode\n");
+       }
+
        while (fgets(buf, sizeof(buf), src_fp) != NULL) {
                gint r = 0;
 
@@ -2110,8 +2139,10 @@ gint canonicalize_file(FILE *src_fp, FILE *dest_fp)
                }
 
                if (r == EOF) {
-                       g_warning("writing to destination file failed.\n");
-
+                       g_warning("writing to %s failed.\n", dest);
+                       fclose(dest_fp);
+                       fclose(src_fp);
+                       unlink(dest);
                        return -1;
                }
        }
@@ -2121,7 +2152,18 @@ gint canonicalize_file(FILE *src_fp, FILE *dest_fp)
                        err = TRUE;
        }
 
+       if (ferror(src_fp)) {
+               FILE_OP_ERROR(src, "fread");
+               err = TRUE;
+       }
+       fclose(src_fp);
+       if (fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "fclose");
+               err = TRUE;
+       }
+
        if (err) {
+               unlink(dest);
                return -1;
        }
 
@@ -2130,37 +2172,19 @@ gint canonicalize_file(FILE *src_fp, FILE *dest_fp)
 
 gint canonicalize_file_replace(const gchar *file)
 {
-       gchar *tmp_file, *dirname;
-       FILE *src, *dest;
+       gchar *tmp_file;
 
-       src = fopen(file, "r");
+       tmp_file = get_tmp_file();
 
-       dirname = g_dirname(file);
-       dest = get_tmpfile_in_dir(dirname, &tmp_file);
-       g_free(dirname);
-
-       debug_print("Writing canonicalized file to %s\n", tmp_file);
-
-       if (canonicalize_file(src, dest) < 0) {
-               fclose(dest);
-               fclose(src);
-
-               g_free(tmp_file);
+       if (canonicalize_file(file, tmp_file) < 0)
                return -1;
-       }
-       fclose(dest);
-       fclose(src);
 
-       unlink(file);
-       if (rename(tmp_file, file) < 0) {
+       if (move_file(tmp_file, file, TRUE) < 0) {
                FILE_OP_ERROR(file, "rename");
                unlink(tmp_file);
-
-               g_free(tmp_file);
                return -1;
        }
 
-       g_free(tmp_file);
        return 0;
 }
 
@@ -2185,7 +2209,7 @@ FILE *my_tmpfile(void)
        gint fd;
        FILE *fp;
 
-       tmpdir = g_get_tmp_dir();
+       tmpdir = get_tmp_dir();
        tmplen = strlen(tmpdir);
        progname = g_get_prgname();
        proglen = strlen(progname);
index f5a1a561e4a68cc8e3f737f35222775a3d0dc96f..d1c0762f2c5cb7e3b38714600d8b8149c0415aea 100644 (file)
@@ -302,6 +302,7 @@ gchar *get_mbox_cache_dir   (void);
 gchar *get_mime_tmp_dir                (void);
 gchar *get_template_dir                (void);
 gchar *get_header_cache_dir     (void);
+gchar *get_tmp_dir             (void);
 gchar *get_tmp_file            (void);
 gchar *get_domain_name         (void);
 
@@ -330,16 +331,18 @@ gint remove_expired_files (const gchar    *dir,
                                 guint           hours);
 gint remove_dir_recursive      (const gchar    *dir);
 gint copy_file                 (const gchar    *src,
-                                const gchar    *dest);
+                                const gchar    *dest,
+                                gboolean        keep_backup);
 gint move_file                 (const gchar    *src,
+                                const gchar    *dest,
+                                gboolean        overwrite);
+gint canonicalize_file         (const gchar    *src,
                                 const gchar    *dest);
 gint canonicalize_file_replace (const gchar    *file);
 gint change_file_mode_rw       (FILE           *fp,
                                 const gchar    *file);
 FILE *my_tmpfile               (void);
 FILE *str_open_as_stream       (const gchar    *str);
-FILE *get_tmpfile_in_dir       (const gchar    *dir,
-                                gchar          **filename);
 
 /* process execution */
 gint execute_async             (gchar *const    argv[]);