LCOV - code coverage report
Current view: top level - common - replicate_utils.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 12 15 80.0 %
Date: 2011-08-21 Functions: 2 2 100.0 %
Branches: 2 4 50.0 %

           Branch data     Line data    Source code
       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
       6                 :            :  *
       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.
      11                 :            :  *
      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.
      16                 :            :  *
      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
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "replicate_utils.h"
      25                 :            : 
      26                 :            : #include "xapian/error.h"
      27                 :            : 
      28                 :            : #include "io_utils.h"
      29                 :            : 
      30                 :            : #ifdef __WIN32__
      31                 :            : # include "msvc_posix_wrapper.h"
      32                 :            : #endif
      33                 :            : #include "safeerrno.h"
      34                 :            : #include "safefcntl.h"
      35                 :            : #include "safesysstat.h"
      36                 :            : #include "safeunistd.h"
      37                 :            : 
      38                 :            : #include <sys/types.h>
      39                 :            : 
      40                 :            : #include <string>
      41                 :            : 
      42                 :            : using namespace std;
      43                 :            : 
      44                 :            : int
      45                 :         93 : create_changeset_file(const string & changeset_dir,
      46                 :            :                       const string & filename,
      47                 :            :                       string & changes_name)
      48                 :            : {
      49                 :         93 :     changes_name = changeset_dir;
      50                 :         93 :     changes_name += '/';
      51                 :         93 :     changes_name += filename;
      52                 :            : #ifdef __WIN32__
      53                 :            :     int changes_fd = msvc_posix_open(changes_name.c_str(),
      54                 :            :                                      O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
      55                 :            : #else
      56                 :            :     int changes_fd = open(changes_name.c_str(),
      57                 :         93 :                           O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
      58                 :            : #endif
      59         [ -  + ]:         93 :     if (changes_fd < 0) {
      60                 :          0 :         string message("Couldn't open changeset to write: ");
      61                 :          0 :         message += changes_name;
      62                 :          0 :         throw Xapian::DatabaseError(message, errno);
      63                 :            :     }
      64                 :         93 :     return changes_fd;
      65                 :            : }
      66                 :            : 
      67                 :            : void
      68                 :       1466 : write_and_clear_changes(int changes_fd, string & buf, size_t bytes)
      69                 :            : {
      70         [ +  - ]:       1466 :     if (changes_fd != -1) {
      71                 :       1466 :         io_write(changes_fd, buf.data(), bytes);
      72                 :            :     }
      73                 :       1466 :     buf.erase(0, bytes);
      74                 :       1466 : }

Generated by: LCOV version 1.8