From 9c14956c51a6a677a4abfc15d806937e544ce99c Mon Sep 17 00:00:00 2001
From: mfava <maria.fava@cern.ch>
Date: Wed, 15 Apr 2020 20:57:19 +0200
Subject: [PATCH] applied modifications
---
src/ADDHCmd.cpp | 37 ++++++++++++++++++++-----------------
tests/test_ADDHCmd.cpp | 4 +---
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/ADDHCmd.cpp b/src/ADDHCmd.cpp
index 7915822..3608b12 100644
--- a/src/ADDHCmd.cpp
+++ b/src/ADDHCmd.cpp
@@ -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
diff --git a/tests/test_ADDHCmd.cpp b/tests/test_ADDHCmd.cpp
index 14d4197..9a67c42 100644
--- a/tests/test_ADDHCmd.cpp
+++ b/tests/test_ADDHCmd.cpp
@@ -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_;
}
};
--
GitLab