Commit 9c14956c authored by Maria Fava's avatar Maria Fava
Browse files

applied modifications

parent 1998a2e6
Pipeline #1562449 passed with stage
in 3 minutes and 7 seconds
......@@ -31,8 +31,7 @@ ADDHCmd::ADDHCmd() :
char hostname[_SC_HOST_NAME_MAX];
gethostname(hostname, _SC_HOST_NAME_MAX);
std::string hostnameString(hostname);
this->m_filePathPrefix = Config::instance().getValue("outputDirPrefix",
std::string());
this->m_filePathPrefix = Config::instance().getValue("outputDirPrefix", "");
}
ADDHCmd::~ADDHCmd() {}
......@@ -95,23 +94,27 @@ void ADDHCmd::commandReceived(ntof::dim::DIMCmd &cmdData)
bool ADDHCmd::isValidPath(const std::string &filePath,
const std::string &m_filePathPrefix)
{
bfs::path absPath = filePath;
if (filePath[0] != '/')
if (m_filePathPrefix != "")
{
// filePath is relative, convert to m_filePathPrefix/filePath form
absPath = m_filePathPrefix + "/" + filePath;
}
try
{
absPath = bfs::canonical(absPath).string();
}
catch (std::exception const &e)
{
// No such file or directory
return false;
bfs::path absPath = filePath;
if (filePath[0] != '/')
{
// filePath is relative, convert to m_filePathPrefix/filePath form
absPath = m_filePathPrefix + "/" + filePath;
}
try
{
absPath = bfs::canonical(absPath).string();
}
catch (std::exception const &e)
{
// No such file or directory
return false;
}
return (absPath.string().compare(0, m_filePathPrefix.length(),
m_filePathPrefix) == 0);
}
return (absPath.string().compare(0, m_filePathPrefix.length(),
m_filePathPrefix) == 0);
return true;
}
} // namespace addh
......
......@@ -77,7 +77,7 @@ public:
void validatePathCheck()
{
ADDHCmd *addhCmd_ = new ADDHCmd();
std::shared_ptr<ADDHCmd> addhCmd_(new ADDHCmd);
bfs::path correct_prefixed_path = m_correct_prefix_dir / "correct_path";
bfs::create_directories(correct_prefixed_path);
......@@ -115,8 +115,6 @@ public:
EQ(false,
addhCmd_->isValidPath(correct_prefixed_path.string() + "/../..",
m_correct_prefix_dir.string()));
delete addhCmd_;
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment