Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/mbox/mbox-save.c @ 13:bb294faf7379 HEAD
"Critical errors" aren't displayed to users anymore, ie. anything that is
not a predefined human readable error message is written into log file and
user gets only "Internal error [timestamp]".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 22 Aug 2002 17:50:16 +0300 |
parents | 1b34ec11fff8 |
children | a946ce1f09b7 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "lib.h" | |
4 #include "hostpid.h" | |
5 #include "iobuffer.h" | |
6 #include "mbox-index.h" | |
7 #include "mbox-lock.h" | |
8 #include "mbox-storage.h" | |
9 | |
10 #include <stdlib.h> | |
11 #include <unistd.h> | |
12 #include <fcntl.h> | |
13 | |
14 int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[], | |
15 time_t internal_date, IOBuffer *data, size_t data_size) | |
16 { | |
17 IndexMailbox *ibox = (IndexMailbox *) box; | |
18 off_t pos; | |
19 int fd, failed; | |
20 | |
21 if (box->readonly) { | |
22 mail_storage_set_error(box->storage, "Mailbox is read-only"); | |
23 return FALSE; | |
24 } | |
25 | |
26 if (!index_mailbox_fix_custom_flags(ibox, &flags, custom_flags)) | |
27 return mail_storage_set_index_error(ibox); | |
28 | |
29 /* append the data into mbox file */ | |
30 fd = open(ibox->index->mbox_path, O_RDWR | O_CREAT); | |
31 if (fd == -1) { | |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
32 mail_storage_set_critical(box->storage, "Can't open mbox file " |
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
33 "%s: %m", ibox->index->mbox_path); |
0 | 34 return FALSE; |
35 } | |
36 | |
37 if (!mbox_lock(ibox->index, ibox->index->mbox_path, fd)) { | |
38 (void)close(fd); | |
39 return mail_storage_set_index_error(ibox); | |
40 } | |
41 | |
42 failed = FALSE; | |
43 | |
44 pos = lseek(fd, 0, SEEK_END); | |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
45 if (pos == -1) { |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
46 mail_storage_set_critical(box->storage, |
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
47 "lseek() failed for mbox file %s: %m", |
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
48 ibox->index->mbox_path); |
0 | 49 failed = TRUE; |
50 } | |
51 | |
52 if (!failed && !index_storage_save_into_fd(box->storage, fd, | |
53 ibox->index->mbox_path, | |
54 data, data_size)) { | |
55 /* failed, truncate file back to original size */ | |
56 (void)ftruncate(fd, pos); | |
57 failed = TRUE; | |
58 } | |
59 | |
60 (void)mbox_unlock(ibox->index, ibox->index->mbox_path, fd); | |
61 (void)close(fd); | |
62 return !failed; | |
63 } |