2015-09-29 14:29:10 +02:00
|
|
|
#include "ProgramOptions.h"
|
|
|
|
#include <cstring>
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/assert/assert.h>
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
using namespace cryfs::program_options;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2015-10-17 18:31:17 +02:00
|
|
|
using boost::optional;
|
2015-11-17 10:49:35 +01:00
|
|
|
namespace bf = boost::filesystem;
|
2015-09-29 14:29:10 +02:00
|
|
|
|
2015-11-17 10:49:35 +01:00
|
|
|
ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir, const optional<bf::path> &configFile,
|
2015-11-13 00:06:53 +01:00
|
|
|
bool foreground, const optional<double> &unmountAfterIdleMinutes,
|
2015-11-17 10:49:35 +01:00
|
|
|
const optional<bf::path> &logFile, const optional<string> &cipher,
|
2016-02-13 10:46:05 +01:00
|
|
|
const vector<char*> &fuseOptions)
|
2015-11-17 10:49:35 +01:00
|
|
|
:_baseDir(baseDir), _mountDir(nullptr), _configFile(configFile), _foreground(foreground),
|
2016-02-13 10:46:05 +01:00
|
|
|
_cipher(cipher), _unmountAfterIdleMinutes(unmountAfterIdleMinutes), _logFile(logFile), _fuseOptions(fuseOptions) {
|
2015-11-17 10:49:35 +01:00
|
|
|
|
|
|
|
string mountDirStr = mountDir.native();
|
|
|
|
_mountDir = new char[mountDirStr.size()+1];
|
|
|
|
std::memcpy(_mountDir, mountDirStr.c_str(), mountDirStr.size()+1);
|
2015-09-29 14:29:10 +02:00
|
|
|
// Fuse needs the mountDir passed as first option (first option = position 1, since 0 is the executable name)
|
|
|
|
ASSERT(_fuseOptions.size() >= 1, "There has to be one parameter at least for the executable name");
|
|
|
|
_fuseOptions.insert(_fuseOptions.begin()+1, _mountDir);
|
|
|
|
}
|
|
|
|
|
2015-10-17 21:33:41 +02:00
|
|
|
ProgramOptions::ProgramOptions(ProgramOptions &&rhs)
|
|
|
|
:_baseDir(std::move(rhs._baseDir)), _mountDir(std::move(rhs._mountDir)), _configFile(std::move(rhs._configFile)),
|
2015-11-12 20:43:11 +01:00
|
|
|
_foreground(std::move(rhs._foreground)), _cipher(std::move(rhs._cipher)),
|
|
|
|
_unmountAfterIdleMinutes(std::move(rhs._unmountAfterIdleMinutes)), _logFile(std::move(rhs._logFile)),
|
2016-02-13 10:46:05 +01:00
|
|
|
_fuseOptions(std::move(rhs._fuseOptions)) {
|
2015-10-17 21:33:41 +02:00
|
|
|
rhs._mountDir = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
ProgramOptions::~ProgramOptions() {
|
2015-10-17 21:33:41 +02:00
|
|
|
if (_mountDir != nullptr) {
|
|
|
|
delete[] _mountDir;
|
|
|
|
}
|
2015-09-29 14:29:10 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:49:35 +01:00
|
|
|
const bf::path &ProgramOptions::baseDir() const {
|
2015-09-29 14:29:10 +02:00
|
|
|
return _baseDir;
|
|
|
|
}
|
|
|
|
|
2015-11-17 10:49:35 +01:00
|
|
|
bf::path ProgramOptions::mountDir() const {
|
|
|
|
return bf::path(_mountDir);
|
2015-09-29 14:29:10 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:49:35 +01:00
|
|
|
const optional<bf::path> &ProgramOptions::configFile() const {
|
2015-09-29 14:39:10 +02:00
|
|
|
return _configFile;
|
|
|
|
}
|
|
|
|
|
2015-10-15 03:38:44 +02:00
|
|
|
bool ProgramOptions::foreground() const {
|
|
|
|
return _foreground;
|
|
|
|
}
|
|
|
|
|
2015-11-13 00:06:53 +01:00
|
|
|
const optional<double> &ProgramOptions::unmountAfterIdleMinutes() const {
|
2015-11-12 20:43:11 +01:00
|
|
|
return _unmountAfterIdleMinutes;
|
|
|
|
}
|
|
|
|
|
2015-11-17 10:49:35 +01:00
|
|
|
const optional<bf::path> &ProgramOptions::logFile() const {
|
2015-10-17 18:31:17 +02:00
|
|
|
return _logFile;
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:53:15 +01:00
|
|
|
const optional<string> &ProgramOptions::cipher() const {
|
|
|
|
return _cipher;
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
const vector<char *> &ProgramOptions::fuseOptions() const {
|
|
|
|
return _fuseOptions;
|
|
|
|
}
|