+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
( 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
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;
}
if (fcntl(fd, F_SETLK, &fl) == -1) {
g_warning("can't fnctl %s", base);
- return -1;
} else {
fcntled = TRUE;
}
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)
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);