LCOV - lcov.info - ept/debtags/maint/path.cc

LTP GCOV extension - code coverage report
Current view: | directory - ept/debtags/maint - path.cc
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 54
Code covered: | 90.7 % |  | Executed lines: | 49

           1                 : // -*- mode: c++; indent-tabs-mode: t -*-
           2                 :
           3                 : /** \file
           4                 :  * debtags 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/debtags/maint/path.h>
          26                 : #include <ept/config.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 debtags {
          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, ".debtags");
          47                 :
          48               0 :         return rcdir;
          49                 : }
          50                 :
          51                 :
          52             732 : Path &Path::instance() {
          53             732 :         if (!s_instance) {
          54               1 :                 s_instance = new Path;
          55               1 :                 instance().m_debtagsSourceDir = DEBTAGS_DB_DIR;
          56               1 :                 instance().m_debtagsIndexDir = DEBTAGS_DB_DIR;
          57               2 :                 instance().m_debtagsUserSourceDir = userdir();
          58               2 :                 instance().m_debtagsUserIndexDir = userdir();
          59                 :         }
          60             732 :         return *s_instance;
          61                 : }
          62                 :
          63              12 : int Path::access( const std::string &s, int m ) {
          64              12 :         return ::access( s.c_str(), m );
          65                 : }
          66                 :
          67             300 : time_t Path::timestamp( const std::string& file ) {
          68             300 :         std::auto_ptr<struct stat> st = wibble::sys::fs::stat(file);
          69             580 :         return st.get() == NULL ? 0 : st->st_mtime;
          70                 : }
          71                 :
          72              62 : void Path::setDebtagsSourceDir( const std::string &s )
          73                 : {
          74              62 :         instance().m_debtagsSourceDir = s;
          75              62 : }
          76              62 : void Path::setDebtagsIndexDir( const std::string &s )
          77                 : {
          78              62 :         instance().m_debtagsIndexDir = s;
          79              62 : }
          80              62 : void Path::setDebtagsUserSourceDir( const std::string &s )
          81                 : {
          82              62 :         instance().m_debtagsUserSourceDir = s;
          83              62 : }
          84              62 : void Path::setDebtagsUserIndexDir( const std::string &s )
          85                 : {
          86              62 :         instance().m_debtagsUserIndexDir = s;
          87              62 : }
          88                 :
          89              72 : std::string Path::debtagsSourceDir() { return instance().m_debtagsSourceDir; }
          90             121 : std::string Path::debtagsIndexDir() { return instance().m_debtagsIndexDir; }
          91              82 : std::string Path::debtagsUserSourceDir() { return instance().m_debtagsUserSourceDir; }
          92             205 : std::string Path::debtagsUserIndexDir() { return instance().m_debtagsUserIndexDir; }
          93                 :
          94              33 : std::string Path::vocabulary() {
          95              33 :         return str::joinpath(debtagsIndexDir(), "vocabulary");
          96                 : }
          97                 :
          98              32 : std::string Path::vocabularyIndex() {
          99              32 :         return str::joinpath(debtagsIndexDir(), "vocabulary.idx");
         100                 : }
         101                 :
         102              65 : std::string Path::userVocabulary() {
         103              65 :         return str::joinpath(debtagsUserIndexDir(), "vocabulary");
         104                 : }
         105                 :
         106              65 : std::string Path::userVocabularyIndex() {
         107              65 :         return str::joinpath(debtagsUserIndexDir(), "vocabulary.idx");
         108                 : }
         109                 :
         110              11 : std::string Path::tagdb() {
         111              11 :         return str::joinpath(debtagsIndexDir(), "package-tags");
         112                 : }
         113                 :
         114              11 : std::string Path::tagdbIndex() {
         115              11 :         return str::joinpath(debtagsIndexDir(), "package-tags.idx");
         116                 : }
         117                 :
         118              22 : std::string Path::userTagdb() {
         119              22 :         return str::joinpath(debtagsUserIndexDir(), "package-tags");
         120                 : }
         121                 :
         122              22 : std::string Path::userTagdbIndex() {
         123              22 :         return str::joinpath(debtagsUserIndexDir(), "package-tags.idx");
         124                 : }
         125                 :
         126               0 : std::string Path::pkgidx() {
         127               0 :         return str::joinpath(debtagsIndexDir(), "pkgidx.idx");
         128                 : }
         129                 :
         130               0 : std::string Path::userPkgidx() {
         131               0 :         return str::joinpath(debtagsUserIndexDir(), "pkgidx.idx");
         132                 : }
         133                 :
         134                 :
         135                 : Path *Path::s_instance = 0;
         136                 :
         137                 : }
         138                 : }
         139                 :
         140                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6