annotate src/lib/fdatasync-path.c @ 22955:812e5c961328

fts: Indexing virtual mailbox didn't always index the last mails
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 03 May 2018 18:33:00 +0300
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
1 /* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
7329
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "fdatasync-path.h"
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include <fcntl.h>
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include <unistd.h>
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 int fdatasync_path(const char *path)
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 {
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 int fd, ret = 0;
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 /* Directories need to be opened as read-only.
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 fsync() doesn't appear to care about it. */
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 fd = open(path, O_RDONLY);
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 if (fd == -1)
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 return -1;
8012
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
18 if (fdatasync(fd) < 0) {
8795
ebfcfa35b4f4 fdatasync_path(): Ignore EINVAL errors (Linux+CIFS).
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
19 /* Some OSes/FSes don't allow fsyncing directores. Silently
ebfcfa35b4f4 fdatasync_path(): Ignore EINVAL errors (Linux+CIFS).
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
20 ignore the problem. */
8012
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
21 if (errno == EBADF) {
8795
ebfcfa35b4f4 fdatasync_path(): Ignore EINVAL errors (Linux+CIFS).
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
22 /* e.g. NetBSD */
ebfcfa35b4f4 fdatasync_path(): Ignore EINVAL errors (Linux+CIFS).
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
23 } else if (errno == EINVAL) {
ebfcfa35b4f4 fdatasync_path(): Ignore EINVAL errors (Linux+CIFS).
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
24 /* e.g. Linux+CIFS */
8012
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
25 } else {
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
26 ret = -1;
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
27 }
164bdad216b8 fdatasync_path(): Ignore EBADF errors, it probably means directory fsyncing
Timo Sirainen <tss@iki.fi>
parents: 7329
diff changeset
28 }
14691
3945a3646c67 Changed i_close_fd() API to set the fd to -1 after closing.
Timo Sirainen <tss@iki.fi>
parents: 14687
diff changeset
29 i_close_fd(&fd);
7329
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 return ret;
d2b10facb504 Moved fdatasync_path() to a global function.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 }