00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "replicate_utils.h"
00025
00026 #include "xapian/error.h"
00027
00028 #include "io_utils.h"
00029
00030 #ifdef __WIN32__
00031 # include "msvc_posix_wrapper.h"
00032 #endif
00033 #include "safeerrno.h"
00034 #include "safefcntl.h"
00035 #include "safesysstat.h"
00036 #include "safeunistd.h"
00037
00038 #include <sys/types.h>
00039
00040 #include <string>
00041
00042 using namespace std;
00043
00044 int
00045 create_changeset_file(const string & changeset_dir,
00046 const string & filename,
00047 string & changes_name)
00048 {
00049 changes_name = changeset_dir;
00050 changes_name += '/';
00051 changes_name += filename;
00052 #ifdef __WIN32__
00053 int changes_fd = msvc_posix_open(changes_name.c_str(),
00054 O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
00055 #else
00056 int changes_fd = open(changes_name.c_str(),
00057 O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
00058 #endif
00059 if (changes_fd < 0) {
00060 string message("Couldn't open changeset to write: ");
00061 message += changes_name;
00062 throw Xapian::DatabaseError(message, errno);
00063 }
00064 return changes_fd;
00065 }
00066
00067 void
00068 write_and_clear_changes(int changes_fd, string & buf, size_t bytes)
00069 {
00070 if (changes_fd != -1) {
00071 io_write(changes_fd, buf.data(), bytes);
00072 }
00073 buf.erase(0, bytes);
00074 }