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 <umount.hpp>
10 :
11 : #include <backends.hpp>
12 : #include <cmdline.hpp>
13 : #include <kdb.hpp>
14 :
15 : #include <iostream>
16 :
17 : using namespace std;
18 : using namespace kdb;
19 : using namespace kdb::tools;
20 :
21 318 : UmountCommand::UmountCommand ()
22 : {
23 318 : }
24 :
25 240 : int UmountCommand::execute (Cmdline const & cl)
26 : {
27 480 : if (cl.arguments.size () != 1) throw invalid_argument ("1 argument required");
28 :
29 480 : KeySet conf;
30 480 : Key parentKey (Backends::mountpointsPath, KEY_END);
31 240 : kdb.get (conf, parentKey);
32 240 : printWarnings (cerr, parentKey, cl.verbose, cl.debug);
33 :
34 720 : std::string name = cl.createKey (0).getName ();
35 :
36 240 : if (cl.verbose) Backends::findBackend (name, conf, true);
37 :
38 240 : if (Backends::umount (name, conf) == 0)
39 : {
40 3 : cerr << "Mountpoint " << name << " does not exist" << endl;
41 : return 1;
42 : }
43 :
44 239 : kdb.set (conf, parentKey);
45 :
46 : return 0;
47 : }
48 :
49 636 : UmountCommand::~UmountCommand ()
50 : {
51 7482 : }
|