LCOV - code coverage report
Current view: top level - src/tools/kdb - specmount.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 37 43 86.0 %
Date: 2019-09-12 12:28:41 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief source file of spec mount command
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : 
      11             : #include <cmdline.hpp>
      12             : #include <specmount.hpp>
      13             : #include <specreader.hpp>
      14             : 
      15             : #include <fstream>
      16             : #include <iostream>
      17             : #include <iterator>
      18             : #include <string>
      19             : #include <vector>
      20             : 
      21             : using namespace std;
      22             : using namespace kdb;
      23             : using namespace kdb::tools;
      24             : 
      25         167 : SpecMountCommand::SpecMountCommand ()
      26             : {
      27         167 : }
      28             : 
      29          11 : void SpecMountCommand::setMountpoint (Cmdline const & cl)
      30             : {
      31          22 :         if (cl.arguments.empty ())
      32             :         {
      33           0 :                 throw invalid_argument ("you need to provide one argument: spec-mountpoint");
      34             :         }
      35             : 
      36          33 :         mp = cl.createKey (0).getName ();
      37             : 
      38          22 :         if (mp.at (0) != '/')
      39             :         {
      40           0 :                 throw invalid_argument (mp + " is not a cascading mountpoint");
      41             :         }
      42          11 : }
      43             : 
      44          11 : void SpecMountCommand::buildBackend (Cmdline const & cl)
      45             : {
      46          22 :         SpecReader sr;
      47             : 
      48          22 :         kdb::KeySet specToRead;
      49          22 :         kdb.get (specToRead, "spec" + mp);
      50          66 :         specToRead = specToRead.cut (Key ("spec" + mp, KEY_END));
      51             : 
      52          11 :         sr.readSpecification (specToRead);
      53             : 
      54          22 :         SpecReader::Backends const & backends = sr.getBackends ();
      55             : 
      56          44 :         for (auto & p : backends)
      57             :         {
      58          33 :                 auto backend = p.second;
      59          11 :                 if (cl.verbose)
      60             :                 {
      61           0 :                         std::cout << "Got mountpoint from " << p.first.getName () << " with " << backend.nodes
      62           0 :                                   << " nodes, configfile: " << backend.getConfigFile () << " and mountpoint: " << backend.getMountpoint ()
      63           0 :                                   << std::endl;
      64             :                 }
      65             : 
      66          55 :                 backend.setBackendConfig (cl.getPluginsConfig ("system/"));
      67          33 :                 backend.needPlugin (cl.resolver);
      68          44 :                 backend.needPlugin ("storage");
      69             : 
      70          22 :                 backend.addPlugins (parseArguments (cl.plugins));
      71             : 
      72          11 :                 const int alreadyRead = 1; // we already read mountpoint
      73          22 :                 if (cl.arguments.size () <= alreadyRead)
      74             :                 {
      75          55 :                         backend.addPlugins (parseArguments (cl.arguments.begin () + alreadyRead, cl.arguments.end ()));
      76             :                 }
      77             : 
      78             :                 // Call it a day
      79          11 :                 outputMissingRecommends (backend.resolveNeeds (cl.withRecommends));
      80          22 :                 Backends::umount (backend.getMountpoint (), mountConf);
      81          11 :                 backend.serialize (mountConf);
      82             :         }
      83             : 
      84          22 :         if (!cl.quiet && backends.empty ())
      85             :         {
      86           0 :                 std::cout << "No metadata \"mountpoint\" found below spec" << mp << std::endl;
      87             :         }
      88          11 : }
      89             : 
      90             : /**
      91             :  * @brief Its quite linear whats going on, but there are many steps involved
      92             :  *
      93             :  * @param cl the commandline
      94             :  *
      95             :  * @retval 0 on success (otherwise exception)
      96             :  */
      97          11 : int SpecMountCommand::execute (Cmdline const & cl)
      98             : {
      99          11 :         readMountConf (cl);
     100             : 
     101          11 :         setMountpoint (cl);
     102             : 
     103          11 :         buildBackend (cl);
     104          11 :         doIt ();
     105             : 
     106          11 :         return 0;
     107             : }
     108             : 
     109         167 : SpecMountCommand::~SpecMountCommand ()
     110             : {
     111        7331 : }

Generated by: LCOV version 1.13