use boost::optional for an optional argument in Fuse class

This commit is contained in:
Francis Banyikwa 2016-06-02 21:58:04 +03:00
parent 92d8f939ac
commit f2b7aac76a
2 changed files with 6 additions and 5 deletions

View File

@ -217,7 +217,7 @@ Fuse::~Fuse() {
_argv.clear();
}
Fuse::Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname)
Fuse::Fuse(Filesystem *fs, const std::string &fstype, const boost::optional<std::string> &fsname)
:_fs(fs), _mountdir(), _running(false), _fstype(fstype), _fsname(fsname) {
}
@ -240,7 +240,7 @@ void Fuse::run(const bf::path &mountdir, const vector<string> &fuseOptions) {
for (const string &option : fuseOptions) {
_argv.push_back(_create_c_string(option));
}
if(!_fsname.empty()) {
if(_fsname != boost::none) {
auto hasNoOption = [&](const char *opt) {
for (const string& it : fuseOptions) {
if (std::strncmp(it.c_str(), opt, std::strlen(opt))) {
@ -251,7 +251,7 @@ void Fuse::run(const bf::path &mountdir, const vector<string> &fuseOptions) {
};
if (hasNoOption("subtype=") && hasNoOption("fsname=")) {
_argv.push_back(_create_c_string("-o"));
_argv.push_back(_create_c_string("fsname="+_fsname));
_argv.push_back(_create_c_string("fsname="+*_fsname));
_argv.push_back(_create_c_string("-o"));
_argv.push_back(_create_c_string("subtype="+_fstype));
}

View File

@ -8,6 +8,7 @@
#include <vector>
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <cpp-utils/macros.h>
namespace fspp {
@ -18,7 +19,7 @@ class Filesystem;
class Fuse final {
public:
explicit Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname=std::string());
explicit Fuse(Filesystem *fs, const std::string &fstype, const boost::optional<std::string> &fsname);
~Fuse();
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
@ -66,7 +67,7 @@ private:
std::vector<char*> _argv;
bool _running;
std::string _fstype;
std::string _fsname;
boost::optional<std::string> _fsname;
DISALLOW_COPY_AND_ASSIGN(Fuse);
};