LCOV - code coverage report
Current view: top level - src/tools/kdb - fstab.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 4 35 11.4 %
Date: 2019-09-12 12:28:41 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <fstab.hpp>
      10             : 
      11             : #include <cmdline.hpp>
      12             : #include <kdb.hpp>
      13             : #include <keysetio.hpp>
      14             : 
      15             : #include <iostream>
      16             : #include <string>
      17             : 
      18             : using namespace std;
      19             : using namespace kdb;
      20             : 
      21          78 : FstabCommand::FstabCommand ()
      22             : {
      23          78 : }
      24             : 
      25           0 : int FstabCommand::execute (Cmdline const & cl)
      26             : {
      27           0 :         int argc = cl.arguments.size ();
      28           0 :         if (argc != 5 && argc != 6 && argc != 7)
      29             :         {
      30           0 :                 throw invalid_argument ("number of arguments not correct, need 5, 6 or 7");
      31             :         }
      32             : 
      33           0 :         KeySet conf;
      34           0 :         Key parentKey = cl.createKey (0);
      35           0 :         kdb.get (conf, parentKey);
      36           0 :         printWarnings (cerr, parentKey, cl.verbose, cl.debug);
      37           0 :         Key k = conf.lookup (parentKey);
      38             : 
      39           0 :         if (!k)
      40             :         {
      41           0 :                 k = cl.createKey (0);
      42             :                 conf.append (k);
      43             :         }
      44             : 
      45           0 :         std::string keyname = k.getName ();
      46             : 
      47           0 :         string dumpfreq = "0";
      48           0 :         if (argc >= 6)
      49             :         {
      50           0 :                 dumpfreq = cl.arguments[5].c_str ();
      51             :         }
      52             : 
      53           0 :         string passno = "0";
      54           0 :         if (argc >= 7)
      55             :         {
      56           0 :                 passno = cl.arguments[6].c_str ();
      57             :         }
      58             : 
      59           0 :         kdb::KeySet config (20, *kdb::Key (keyname + "/ZZZNewFstabName", KEY_END),
      60           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/device", KEY_VALUE, cl.arguments[1].c_str (), KEY_END),
      61           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/mpoint", KEY_VALUE, cl.arguments[2].c_str (), KEY_END),
      62           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/type", KEY_VALUE, cl.arguments[3].c_str (), KEY_END),
      63           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/options", KEY_VALUE, cl.arguments[4].c_str (), KEY_END),
      64           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/dumpfreq", KEY_VALUE, dumpfreq.c_str (), KEY_END),
      65           0 :                             *kdb::Key (keyname + "/ZZZNewFstabName/passno", KEY_VALUE, passno.c_str (), KEY_END), KS_END);
      66             : 
      67           0 :         conf.append (config);
      68             : 
      69           0 :         if (cl.verbose)
      70             :         {
      71           0 :                 cout << conf;
      72             :         }
      73             : 
      74           0 :         kdb.set (conf, parentKey);
      75           0 :         printWarnings (cerr, parentKey, cl.verbose, cl.debug);
      76             : 
      77           0 :         return 0;
      78             : }
      79             : 
      80         156 : FstabCommand::~FstabCommand ()
      81             : {
      82        7242 : }

Generated by: LCOV version 1.13