LTP GCOV extension - code coverage report
Current view: directory - ept/debtags/maint - sourcedir.cc
Test: lcov.info
Date: 2008-08-14 Instrumented lines: 57
Code covered: 75.4 % Executed lines: 43

       1                 : #include <ept/debtags/maint/sourcedir.h>
       2                 : #include <ept/debtags/maint/vocabularymerger.h>
       3                 : #include <ept/debtags/maint/path.h>
       4                 : 
       5                 : #include <wibble/string.h>
       6                 : 
       7                 : #include <tagcoll/input/zlib.h>
       8                 : #include <tagcoll/input/stdio.h>
       9                 : 
      10                 : using namespace wibble;
      11                 : 
      12                 : namespace ept {
      13                 : namespace debtags {
      14                 : 
      15             802 : SourceDir::FileType SourceDir::fileType(const std::string& name)
      16                 : {
      17             802 :         if (name[0] == '.') return SKIP;
      18                 : 
      19                 :         // Filenames need to be at least 5 characters long (one char plus
      20                 :         // extension)
      21             622 :         if (name.size() <= 4) return SKIP;
      22                 : 
      23                 :         // Only look at .voc and .tag files
      24             542 :         std::string ext(name, name.size() - 4);
      25             542 :         if (ext == ".voc")
      26              80 :                 return VOC;
      27             462 :         if (ext == ".tag")
      28              80 :                 return TAG;
      29                 : 
      30                 :         // Now look for compressed files, which must have the 4 character extension
      31                 :         // plus the 3 chars of '.gz'
      32             382 :         if (name.size() <= 7) return SKIP;
      33                 : 
      34             302 :         ext = name.substr(name.size() - 7);
      35             302 :         if (ext == ".voc.gz")
      36               0 :                 return VOCGZ;
      37             302 :         if (ext == ".tag.gz")
      38               0 :                 return TAGGZ;
      39                 : 
      40             302 :         return SKIP;
      41                 : }
      42                 : 
      43              20 : time_t SourceDir::timestamp()
      44                 : {
      45              20 :         if (!valid()) return 0;
      46                 : 
      47              20 :         time_t max = 0;
      48             200 :         for (const_iterator d = begin(); d != end(); ++d)
      49                 :         {
      50             180 :                 FileType type = fileType(d->d_name);
      51             180 :                 if (type == SKIP) continue;
      52                 : 
      53              36 :                 time_t ts = Path::timestamp(str::joinpath(path(), d->d_name));
      54              54 :                 if (ts > max) max = ts;
      55              20 :         }
      56                 : 
      57              20 :         return max;
      58                 : }
      59                 : 
      60              62 : time_t SourceDir::vocTimestamp()
      61                 : {
      62              62 :         if (!valid()) return 0;
      63                 : 
      64              60 :         time_t max = 0;
      65             632 :         for (const_iterator d = begin(); d != end(); ++d)
      66                 :         {
      67             572 :                 FileType type = fileType(d->d_name);
      68            1086 :                 if (type != VOC and type != VOCGZ) continue;
      69                 : 
      70              58 :                 time_t ts = Path::timestamp(str::joinpath(path(), d->d_name));
      71             116 :                 if (ts > max) max = ts;
      72              60 :         }
      73                 : 
      74              60 :         return max;
      75                 : }
      76                 : 
      77               0 : time_t SourceDir::tagTimestamp()
      78                 : {
      79               0 :         if (!valid()) return 0;
      80                 : 
      81               0 :         time_t max = 0;
      82               0 :         for (const_iterator d = begin(); d != end(); ++d)
      83                 :         {
      84               0 :                 FileType type = fileType(d->d_name);
      85               0 :                 if (type != TAG and type != TAGGZ) continue;
      86                 : 
      87               0 :                 time_t ts = Path::timestamp(str::joinpath(path(), d->d_name));
      88               0 :                 if (ts > max) max = ts;
      89               0 :         }
      90                 : 
      91               0 :         return max;
      92                 : }
      93                 : 
      94               6 : void SourceDir::readVocabularies(VocabularyMerger& out)
      95                 : {
      96               6 :         if (!valid()) return;
      97                 : 
      98              32 :         for (const_iterator d = begin(); d != end(); ++d)
      99                 :         {
     100              26 :                 FileType type = fileType(d->d_name);
     101              26 :                 if (type == VOC)
     102                 :                 {
     103                 :                         // Read uncompressed data
     104               2 :                         tagcoll::input::Stdio in(str::joinpath(path(), d->d_name));
     105                 : 
     106                 :                         // Read the vocabulary
     107               4 :                         out.read(in);
     108                 :                 }
     109              24 :                 else if (type == VOCGZ)
     110                 :                 {
     111                 :                         // Read compressed data
     112               0 :                         tagcoll::input::Zlib in(str::joinpath(path(), d->d_name));
     113                 : 
     114                 :                         // Read the vocabulary
     115               0 :                         out.read(in);
     116                 :                 }
     117               6 :         }
     118                 : }
     119                 : 
     120                 : }
     121               6 : }
     122                 : 
     123                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6