2 * @brief Utility functions for replication implementations
4 /* Copyright (C) 2010 Richard Boulton
5 * Copyright (C) 2010 Olly Betts
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "replicate_utils.h"
26 #include "xapian/error.h"
29 #include "posixy_wrapper.h"
31 #include "safefcntl.h"
32 #include "safesysstat.h"
33 #include "safeunistd.h"
35 #include <sys/types.h>
43 create_changeset_file(const string
& changeset_dir
,
44 const string
& filename
,
45 string
& changes_name
)
47 changes_name
= changeset_dir
;
49 changes_name
+= filename
;
50 int changes_fd
= posixy_open(changes_name
.c_str(), O_WRONLY
| O_CREAT
| O_TRUNC
| O_CLOEXEC
, 0666);
52 string
message("Couldn't open changeset to write: ");
53 message
+= changes_name
;
54 throw Xapian::DatabaseError(message
, errno
);
60 write_and_clear_changes(int changes_fd
, string
& buf
, size_t bytes
)
62 if (changes_fd
!= -1) {
63 io_write(changes_fd
, buf
.data(), bytes
);