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