Remove unused header include
[xapian.git] / xapian-core / common / replicate_utils.cc
blob523e9ff8e3709bf70348741f9db9eb9007f84f34
1 /** @file replicate_utils.cc
2 * @brief Utility functions for replication implementations
3 */
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
22 #include <config.h>
24 #include "replicate_utils.h"
26 #include "xapian/error.h"
28 #include "io_utils.h"
29 #include "posixy_wrapper.h"
31 #include "safeerrno.h"
32 #include "safefcntl.h"
33 #include "safesysstat.h"
34 #include "safeunistd.h"
36 #include <sys/types.h>
38 #include <string>
40 using namespace std;
42 int
43 create_changeset_file(const string & changeset_dir,
44 const string & filename,
45 string & changes_name)
47 changes_name = changeset_dir;
48 changes_name += '/';
49 changes_name += filename;
50 int changes_fd = posixy_open(changes_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0666);
51 if (changes_fd < 0) {
52 string message("Couldn't open changeset to write: ");
53 message += changes_name;
54 throw Xapian::DatabaseError(message, errno);
56 return changes_fd;
59 void
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);
65 buf.erase(0, bytes);