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'
This commit is contained in:
Colin Leroy 2007-02-08 18:14:23 +00:00
parent 296c72363e
commit 8d64294026
6 changed files with 63 additions and 6 deletions

View file

@ -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

View file

@ -2349,3 +2349,4 @@
( 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

View 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=

View file

@ -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;
}

View 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)

View 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);