LTP GCOV extension - code coverage report
Current view: | directory - ept/textsearch/maint - path.cc
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 29
Code covered: | 82.8 % |  | Executed lines: | 24

           1                 : // -*- mode: c++; indent-tabs-mode: t -*-
           2                 :
           3                 : /** \file
           4                 :  * popcon paths
           5                 :  */
           6                 :
           7                 : /*
           8                 :  * Copyright (C) 2005,2006,2007  Enrico Zini <enrico@debian.org>, Peter Rockai <me@mornfall.net>
           9                 :  *
          10                 :  * This program is free software; you can redistribute it and/or modify
          11                 :  * it under the terms of the GNU General Public License as published by
          12                 :  * the Free Software Foundation; either version 2 of the License, or
          13                 :  * (at your option) any later version.
          14                 :  *
          15                 :  * This program is distributed in the hope that it will be useful,
          16                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
          17                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
          18                 :  * GNU General Public License for more details.
          19                 :  *
          20                 :  * You should have received a copy of the GNU General Public License
          21                 :  * along with this program; if not, write to the Free Software
          22                 :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
          23                 :  */
          24                 :
          25                 : #include <ept/config.h>
          26                 : #include <ept/textsearch/maint/path.h>
          27                 :
          28                 : #include <wibble/exception.h>
          29                 : #include <wibble/sys/fs.h>
          30                 : #include <wibble/string.h>
          31                 :
          32                 : #include <cstdio>
          33                 : #include <cerrno>
          34                 :
          35                 : #include <sys/types.h>
          36                 : #include <sys/stat.h>
          37                 : #include <unistd.h>
          38                 :
          39                 : using namespace std;
          40                 : using namespace wibble;
          41                 :
          42                 : namespace ept {
          43                 : namespace textsearch {
          44                 :
          45             111 : Path &Path::instance() {
          46             111 :         if (!s_instance) {
          47               1 :                 s_instance = new Path;
          48               1 :                 instance().m_indexDir = TEXTSEARCH_DB_DIR;
          49                 :         }
          50             111 :         return *s_instance;
          51                 : }
          52                 :
          53               0 : int Path::access( const std::string &s, int m )
          54                 : {
          55               0 :         return ::access( s.c_str(), m );
          56                 : }
          57                 :
          58              20 : time_t Path::indexTimestamp()
          59                 : {
          60              20 :         string tsfile = str::joinpath(instance().indexDir(), "update-timestamp");
          61              40 :         std::auto_ptr<struct stat> st = wibble::sys::fs::stat(tsfile);
          62              20 :         if (st.get())
          63              18 :                 return st->st_mtime;
          64                 :         else
          65               2 :                 return 0;
          66                 : }
          67                 :
          68               6 : void Path::setTimestamp(time_t ts)
          69                 : {
          70               6 :         string tsfile = str::joinpath(instance().indexDir(), "/update-timestamp");
          71              12 :         FILE* out = fopen(tsfile.c_str(), "wt");
          72               6 :         if (!out)
          73               0 :                 throw wibble::exception::File(tsfile, "opening file for truncate/writing");
          74               6 :         if (fprintf(out, "%ld\n", ts) < 0)
          75               0 :                 throw wibble::exception::File(tsfile, "writing the modification time");
          76               6 :         if (fclose(out) < 0)
          77               0 :                 throw wibble::exception::File(tsfile, "closing the file");
          78               6 : }
          79                 :
          80              22 : void Path::setIndexDir( const std::string &s )
          81                 : {
          82              22 :         instance().m_indexDir = s;
          83              22 : }
          84                 :
          85              37 : std::string Path::indexDir() { return instance().m_indexDir; }
          86              25 : std::string Path::index() { return str::joinpath(instance().m_indexDir, "/index"); }
          87                 :
          88                 : Path *Path::s_instance = 0;
          89                 :
          90                 : }
          91               6 : }
          92                 :
          93                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6