use boost::optional for an optional argument in Fuse class
This commit is contained in:
parent
92d8f939ac
commit
f2b7aac76a
@ -217,7 +217,7 @@ Fuse::~Fuse() {
|
|||||||
_argv.clear();
|
_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) {
|
:_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) {
|
for (const string &option : fuseOptions) {
|
||||||
_argv.push_back(_create_c_string(option));
|
_argv.push_back(_create_c_string(option));
|
||||||
}
|
}
|
||||||
if(!_fsname.empty()) {
|
if(_fsname != boost::none) {
|
||||||
auto hasNoOption = [&](const char *opt) {
|
auto hasNoOption = [&](const char *opt) {
|
||||||
for (const string& it : fuseOptions) {
|
for (const string& it : fuseOptions) {
|
||||||
if (std::strncmp(it.c_str(), opt, std::strlen(opt))) {
|
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=")) {
|
if (hasNoOption("subtype=") && hasNoOption("fsname=")) {
|
||||||
_argv.push_back(_create_c_string("-o"));
|
_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("-o"));
|
||||||
_argv.push_back(_create_c_string("subtype="+_fstype));
|
_argv.push_back(_create_c_string("subtype="+_fstype));
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <cpp-utils/macros.h>
|
#include <cpp-utils/macros.h>
|
||||||
|
|
||||||
namespace fspp {
|
namespace fspp {
|
||||||
@ -18,7 +19,7 @@ class Filesystem;
|
|||||||
|
|
||||||
class Fuse final {
|
class Fuse final {
|
||||||
public:
|
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();
|
~Fuse();
|
||||||
|
|
||||||
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
|
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
|
||||||
@ -66,7 +67,7 @@ private:
|
|||||||
std::vector<char*> _argv;
|
std::vector<char*> _argv;
|
||||||
bool _running;
|
bool _running;
|
||||||
std::string _fstype;
|
std::string _fstype;
|
||||||
std::string _fsname;
|
boost::optional<std::string> _fsname;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Fuse);
|
DISALLOW_COPY_AND_ASSIGN(Fuse);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user