LTP GCOV extension - code coverage report
Current view: | directory - ept/popcon/maint - path.cc
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 42
Code covered: | 97.6 % |  | Executed lines: | 41

           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/popcon/maint/path.h>
          27                 :
          28                 : #include <wibble/sys/fs.h>
          29                 : #include <wibble/string.h>
          30                 :
          31                 : #include <sys/types.h>    // getpwuid, stat, mkdir, getuid
          32                 : #include <sys/stat.h>     // stat, mkdir
          33                 : #include <pwd.h>          // getpwuid
          34                 : #include <unistd.h>               // stat, getuid
          35                 :
          36                 : using namespace wibble;
          37                 :
          38                 : namespace ept {
          39                 : namespace popcon {
          40                 :
          41               2 : static std::string userdir()
          42                 : {
          43               2 :         std::string rcdir;
          44                 :
          45               2 :         struct passwd* udata = getpwuid(getuid());
          46               2 :         rcdir = str::joinpath(udata->pw_dir, ".popcon");
          47                 :
          48               0 :         return rcdir;
          49                 : }
          50                 :
          51                 :
          52             178 : Path &Path::instance() {
          53             178 :         if (!s_instance) {
          54               1 :                 s_instance = new Path;
          55               1 :                 instance().m_popconSourceDir = POPCON_DB_DIR;
          56               1 :                 instance().m_popconIndexDir = POPCON_DB_DIR;
          57               2 :                 instance().m_popconUserSourceDir = userdir();
          58               2 :                 instance().m_popconUserIndexDir = userdir();
          59                 :         }
          60             178 :         return *s_instance;
          61                 : }
          62                 :
          63               2 : int Path::access( const std::string &s, int m ) {
          64               2 :         return ::access( s.c_str(), m );
          65                 : }
          66                 :
          67              49 : time_t Path::timestamp( const std::string& file ) {
          68              49 :         std::auto_ptr<struct stat> st = wibble::sys::fs::stat(file);
          69              90 :         return st.get() == NULL ? 0 : st->st_mtime;
          70                 : }
          71                 :
          72              14 : void Path::setPopconSourceDir( const std::string &s )
          73                 : {
          74              14 :         instance().m_popconSourceDir = s;
          75              14 : }
          76              14 : void Path::setPopconIndexDir( const std::string &s )
          77                 : {
          78              14 :         instance().m_popconIndexDir = s;
          79              14 : }
          80              14 : void Path::setPopconUserSourceDir( const std::string &s )
          81                 : {
          82              14 :         instance().m_popconUserSourceDir = s;
          83              14 : }
          84              14 : void Path::setPopconUserIndexDir( const std::string &s )
          85                 : {
          86              14 :         instance().m_popconUserIndexDir = s;
          87              14 : }
          88                 :
          89              14 : std::string Path::popconSourceDir() { return instance().m_popconSourceDir; }
          90              43 : std::string Path::popconIndexDir() { return instance().m_popconIndexDir; }
          91              14 : std::string Path::popconUserSourceDir() { return instance().m_popconUserSourceDir; }
          92              47 : std::string Path::popconUserIndexDir() { return instance().m_popconUserIndexDir; }
          93                 :
          94              17 : std::string Path::scores() {
          95              17 :         return str::joinpath(popconIndexDir(), "scores");
          96                 : }
          97                 :
          98              17 : std::string Path::scoresIndex() {
          99              17 :         return str::joinpath(popconIndexDir(), "scores.idx");
         100                 : }
         101                 :
         102              20 : std::string Path::userScores() {
         103              20 :         return str::joinpath(popconUserIndexDir(), "scores");
         104                 : }
         105                 :
         106              20 : std::string Path::userScoresIndex() {
         107              20 :         return str::joinpath(popconUserIndexDir(), "scores.idx");
         108                 : }
         109                 :
         110                 : Path *Path::s_instance = 0;
         111                 :
         112                 : }
         113                 : }
         114                 :
         115                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6