LCOV - code coverage report
Current view: top level - tests/harness - backendmanager_singlefile.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 19 22 86.4 %
Date: 2019-06-30 05:20:33 Functions: 4 5 80.0 %
Branches: 15 36 41.7 %

           Branch data     Line data    Source code
       1                 :            : /** @file backendmanager_singlefile.cc
       2                 :            :  * @brief BackendManager subclass for singlefile databases.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2011,2012,2013,2015,2018 Olly Betts
       5                 :            :  * Copyright (C) 2008 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (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 "backendmanager_singlefile.h"
      25                 :            : 
      26                 :            : #include "filetests.h"
      27                 :            : #include "index_utils.h"
      28                 :            : #include "unixcmds.h"
      29                 :            : 
      30                 :            : #include <cstdio> // For rename().
      31                 :            : 
      32                 :            : using namespace std;
      33                 :            : 
      34                 :          1 : BackendManagerSingleFile::BackendManagerSingleFile(const string& datadir_,
      35                 :            :                                                    BackendManager* sub_manager_)
      36                 :            :     : BackendManager(datadir_),
      37                 :            :       sub_manager(sub_manager_),
      38 [ +  - ][ +  - ]:          1 :       cachedir(".singlefile" + sub_manager_->get_dbtype())
      39                 :            : {
      40                 :            :     // Ensure the directory we store cached test databases in exists.
      41         [ +  - ]:          1 :     (void)create_dir_if_needed(cachedir);
      42                 :          1 : }
      43                 :            : 
      44                 :            : std::string
      45                 :         24 : BackendManagerSingleFile::get_dbtype() const
      46                 :            : {
      47         [ +  - ]:         24 :     return "singlefile_" + sub_manager->get_dbtype();
      48                 :            : }
      49                 :            : 
      50                 :            : string
      51                 :        292 : BackendManagerSingleFile::do_get_database_path(const vector<string> & files)
      52                 :            : {
      53                 :        292 :     string db_path = cachedir + "/db";
      54         [ +  + ]:        589 :     for (const string& file : files) {
      55         [ +  - ]:        297 :         db_path += "__";
      56         [ +  - ]:        297 :         db_path += file;
      57                 :            :     }
      58                 :            : 
      59         [ +  + ]:        292 :     if (!file_exists(db_path)) {
      60                 :            :         // No cached DB exists.  Create at a temporary path and rename
      61                 :            :         // so we don't leave a partial DB in place upon failure.
      62         [ +  - ]:         21 :         string tmp_path = db_path + ".tmp";
      63                 :            :         sub_manager->get_database(files).compact(tmp_path,
      64 [ +  - ][ +  - ]:         21 :                                                  Xapian::DBCOMPACT_SINGLE_FILE);
      65         [ -  + ]:         21 :         if (rename(tmp_path.c_str(), db_path.c_str()) < 0) {
      66 [ #  # ][ #  # ]:          0 :             throw Xapian::DatabaseError("rename failed", errno);
      67                 :         21 :         }
      68                 :            :     }
      69                 :            : 
      70                 :        292 :     return db_path;
      71                 :            : }
      72                 :            : 
      73                 :            : Xapian::WritableDatabase
      74                 :          0 : BackendManagerSingleFile::get_writable_database(const string &, const string &)
      75                 :            : {
      76 [ #  # ][ #  # ]:          0 :     throw Xapian::UnimplementedError("Single-file databases don't support writing");
                 [ #  # ]
      77                 :            : }
      78                 :            : 
      79                 :            : string
      80                 :          6 : BackendManagerSingleFile::get_compaction_output_path(const string& name)
      81                 :            : {
      82         [ +  - ]:          6 :     return cachedir + "/" + name;
      83                 :            : }

Generated by: LCOV version 1.11