LTP GCOV extension - code coverage report
Current view: directory - src/libstore - globals.cc
Test: app.info
Date: 2008-11-20 Instrumented lines: 65
Code covered: 90.8 % Executed lines: 59

       1                 : #include "globals.hh"
       2                 : #include "util.hh"
       3                 : 
       4                 : #include <map>
       5                 : #include <algorithm>
       6                 : 
       7                 : 
       8                 : namespace nix {
       9                 : 
      10                 : 
      11            1151 : string nixStore = "/UNINIT";
      12            1704 : string nixDataDir = "/UNINIT";
      13            1704 : string nixLogDir = "/UNINIT";
      14            1704 : string nixStateDir = "/UNINIT";
      15            1704 : string nixDBPath = "/UNINIT";
      16            1704 : string nixConfDir = "/UNINIT";
      17            1704 : string nixLibexecDir = "/UNINIT";
      18            1704 : string nixBinDir = "/UNINIT";
      19            1704 : string nixChrootsDir = "/UNINIT";
      20                 : 
      21                 : bool keepFailed = false;
      22                 : bool keepGoing = false;
      23                 : bool tryFallback = false;
      24                 : Verbosity buildVerbosity = lvlInfo;
      25                 : unsigned int maxBuildJobs = 1;
      26                 : bool readOnlyMode = false;
      27            1704 : string thisSystem = "unset";
      28                 : unsigned int maxSilentTime = 0;
      29            1704 : Paths substituters;
      30                 : bool useBuildHook = true;
      31                 : bool printBuildTrace = false;
      32                 : 
      33                 : 
      34                 : static bool settingsRead = false;
      35                 : 
      36            1151 : static std::map<string, Strings> settings;
      37                 : 
      38                 : 
      39            3228 : string & at(Strings & ss, unsigned int n)
      40                 : {
      41            3228 :     Strings::iterator i = ss.begin();
      42            3228 :     advance(i, n);
      43            3228 :     return *i;
      44                 : }
      45                 : 
      46                 : 
      47             619 : static void readSettings()
      48                 : {
      49             619 :     Path settingsFile = (format("%1%/%2%") % nixConfDir % "nix.conf").str();
      50            1319 :     if (!pathExists(settingsFile)) return;
      51             538 :     string contents = readFile(settingsFile);
      52                 : 
      53             538 :     unsigned int pos = 0;
      54                 : 
      55            4304 :     while (pos < contents.size()) {
      56            1614 :         string line;
      57           45192 :         while (pos < contents.size() && contents[pos] != '\n')
      58           41964 :             line += contents[pos++];
      59            1614 :         pos++;
      60                 : 
      61            1614 :         string::size_type hash = line.find('#');
      62            1614 :         if (hash != string::npos)
      63               0 :             line = string(line, 0, hash);
      64                 : 
      65            1614 :         Strings tokens = tokenizeString(line);
      66            1614 :         if (tokens.empty()) continue;
      67                 : 
      68            1614 :         if (tokens.size() < 2 || at(tokens, 1) != "=")
      69               0 :             throw Error(format("illegal configuration line `%1%' in `%2%'") % line % settingsFile);
      70                 : 
      71            1614 :         string name = at(tokens, 0);
      72                 : 
      73            1614 :         Strings::iterator i = tokens.begin();
      74            1614 :         advance(i, 2);
      75            1614 :         settings[name] = Strings(i, tokens.end());
      76                 :     };
      77                 :     
      78             538 :     settingsRead = true;
      79                 : }
      80                 : 
      81                 : 
      82            2152 : Strings querySetting(const string & name, const Strings & def)
      83                 : {
      84            2152 :     if (!settingsRead) readSettings();
      85            2152 :     std::map<string, Strings>::iterator i = settings.find(name);
      86            2152 :     return i == settings.end() ? def : i->second;
      87                 : }
      88                 : 
      89                 : 
      90            2152 : string querySetting(const string & name, const string & def)
      91                 : {
      92            2152 :     Strings defs;
      93            2152 :     defs.push_back(def);
      94                 : 
      95            2152 :     Strings value = querySetting(name, defs);
      96            2152 :     if (value.size() != 1)
      97               0 :         throw Error(format("configuration option `%1%' should not be a list") % name);
      98                 : 
      99            2152 :     return value.front();
     100                 : }
     101                 : 
     102                 : 
     103             360 : bool queryBoolSetting(const string & name, bool def)
     104                 : {
     105             360 :     string v = querySetting(name, def ? "true" : "false");
     106             720 :     if (v == "true") return true;
     107             299 :     else if (v == "false") return false;
     108                 :     else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
     109               0 :         % name % v);
     110                 : }
     111                 : 
     112                 : 
     113            1127 : unsigned int queryIntSetting(const string & name, unsigned int def)
     114                 : {
     115                 :     int n;
     116            1127 :     if (!string2Int(querySetting(name, int2String(def)), n) || n < 0)
     117               0 :         throw Error(format("configuration setting `%1%' should have an integer value") % name);
     118            1127 :     return n;
     119                 : }
     120                 : 
     121                 : 
     122              46 : void reloadSettings()
     123                 : {
     124              46 :     settingsRead = false;
     125              46 :     settings.clear();
     126              46 : }
     127                 : 
     128               0 :  
     129            1106 : }

Generated by: LTP GCOV extension version 1.6