2007-02-08 [colin] 2.7.2cvs32
authorColin Leroy <colin@colino.net>
Thu, 8 Feb 2007 18:14:23 +0000 (18:14 +0000)
committerColin Leroy <colin@colino.net>
Thu, 8 Feb 2007 18:14:23 +0000 (18:14 +0000)
* src/inc.c
* src/mbox.c
* src/mbox.h
Fix bug 1117, 'fcntl locking code
does not work in mbox.c'

ChangeLog
PATCHSETS
configure.ac
src/inc.c
src/mbox.c
src/mbox.h

index 3a41bb0d31f57ef2bb9aa72a9d1e9355915b2eb5..4ee0de8f7c7ff38b990134bb5d7ac431bc504e60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-02-08 [colin]     2.7.2cvs32
+
+       * src/inc.c
+       * src/mbox.c
+       * src/mbox.h
+               Fix bug 1117, 'fcntl locking code 
+               does not work in mbox.c'
+
 2007-02-08 [colin]     2.7.2cvs31
 
        * src/prefs_account.c
index 2c65bb89e7ad69f50ea649c74fb04a5baabea578..177d9ffa404aec6bee4993ab9f1caa18437a586e 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.213.2.134 -r 1.213.2.135 src/folder.c;  cvs diff -u -r 1.1.2.42 -r 1.1.2.43 src/imap_gtk.c;  ) > 2.7.2cvs29.patchset
 ( cvs diff -u -r 1.3.2.15 -r 1.3.2.16 src/ldapquery.c;  ) > 2.7.2cvs30.patchset
 ( cvs diff -u -r 1.105.2.84 -r 1.105.2.85 src/prefs_account.c;  ) > 2.7.2cvs31.patchset
+( cvs diff -u -r 1.149.2.64 -r 1.149.2.65 src/inc.c;  cvs diff -u -r 1.28.2.32 -r 1.28.2.33 src/mbox.c;  cvs diff -u -r 1.3.2.8 -r 1.3.2.9 src/mbox.h;  ) > 2.7.2cvs32.patchset
index e20e79c30b40c36be6ac3d89f078af5ddb9820aa..d78e196fd864f7af27d05dcfa4351ec0c014f3d5 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=7
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=31
+EXTRA_VERSION=32
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index e64e233454aa38d20eb76a3b4d101751e20dd41e..5ae8eb5fce0cc62b169fb2d7686f2266eb133afc 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1328,7 +1328,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox, PrefsAccount *account
        g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox.%p",
                   get_tmp_dir(), G_DIR_SEPARATOR, mbox);
 
-       if (copy_mbox(mbox, tmp_mbox) < 0) {
+       if (copy_mbox(lockfd, tmp_mbox) < 0) {
                unlock_mbox(mbox, lockfd, LOCK_FLOCK);
                return -1;
        }
index 18cbbf90abed3bc36246a5bf09979a3bac2a4312..c8e53a8aa6c94f582b0b1a08ecc983cc5f3ccc2b 100644 (file)
@@ -417,7 +417,6 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type)
 
                if (fcntl(fd, F_SETLK, &fl) == -1) {
                        g_warning("can't fnctl %s", base);
-                       return -1;
                } else {
                        fcntled = TRUE;
                }
@@ -451,9 +450,58 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type)
        return -1;
 }
 
-gint copy_mbox(const gchar *src, const gchar *dest)
+gint copy_mbox(gint srcfd, const gchar *dest)
 {
-       return copy_file(src, dest, TRUE);
+       FILE *dest_fp;
+       ssize_t n_read;
+       gchar buf[BUFSIZ];
+       gboolean err = FALSE;
+       int save_errno = 0;
+
+       if (srcfd < 0) {
+               return -1;
+       }
+
+       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "fopen");
+               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 ((n_read = read(srcfd, buf, sizeof(buf))) > 0) {
+               if (n_read < sizeof(buf) && errno != 0) {
+                       save_errno = errno;
+                       break;
+               }
+               if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
+                       g_warning("writing to %s failed.\n", dest);
+                       fclose(dest_fp);
+                       g_unlink(dest);
+                       return -1;
+               }
+       }
+
+       if (save_errno != 0) {
+               g_warning("error %d reading mbox: %s\n", save_errno,
+                               strerror(save_errno));
+               err = TRUE;
+       }
+
+       if (fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               g_unlink(dest);
+               return -1;
+       }
+
+       return 0;
 }
 
 void empty_mbox(const gchar *mbox)
index a2e31485043ecaa3f68759b48c3c8b73523cab08..2794b41841663a0e25b98d036e55ba02cc7ec610 100644 (file)
@@ -39,7 +39,7 @@ gint lock_mbox                (const gchar    *base,
 gint unlock_mbox       (const gchar    *base,
                         gint            fd,
                         LockType        type);
-gint copy_mbox         (const gchar    *src,
+gint copy_mbox         (gint            srcfd,
                         const gchar    *dest);
 void empty_mbox                (const gchar    *mbox);