if (dir_paths[i] == nullptr)
return CSR_ERROR_INVALID_PARAMETER;
- dirSet->insert(Client::getAbsolutePath(dir_paths[i]));
+ dirSet->emplace(Client::getAbsolutePath(dir_paths[i]));
}
auto task = std::make_shared<Task>([hExt, user_data, dirSet] {
auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
auto ret = hExt->dispatch<std::pair<int, CsDetected *>>(
- CommandId::GET_DETECTED, std::string(file_path));
+ CommandId::GET_DETECTED, Client::getAbsolutePath(file_path));
if (ret.second)
hExt->add(ResultPtr(ret.second));
if (dir_paths[i] == nullptr || dir_paths[i][0] == '\0')
return CSR_ERROR_INVALID_PARAMETER;
- dirSet.emplace(dir_paths[i]);
+ dirSet.emplace(Client::getAbsolutePath(dir_paths[i]));
}
if (dirSet.size() == 0)
auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
auto ret = hExt->dispatch<std::pair<int, CsDetected *>>(
- CommandId::GET_IGNORED, std::string(file_path));
+ CommandId::GET_IGNORED, Client::getAbsolutePath(file_path));
if (ret.second)
hExt->add(ResultPtr(ret.second));
if (dir_paths[i] == nullptr || dir_paths[i][0] == '\0')
return CSR_ERROR_INVALID_PARAMETER;
- dirSet.emplace(dir_paths[i]);
+ dirSet.emplace(Client::getAbsolutePath(dir_paths[i]));
}
if (dirSet.size() == 0)
#include "service/cs-logic.h"
#include <utility>
-#include <algorithm>
#include <climits>
#include <cerrno>
#include <unistd.h>
return path;
}
+std::string canonicalizePath(const std::string &path, bool checkAccess)
+{
+ auto resolved = resolvePath(path);
+ auto target = File::getPkgPath(resolved);
+
+ if (checkAccess && ::access(target.c_str(), R_OK) != 0) {
+ const int err = errno;
+ if (err == ENOENT)
+ ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target);
+ else if (err == EACCES)
+ ThrowExc(CSR_ERROR_PERMISSION_DENIED,
+ "Perm denied to get real path: " << target);
+ else
+ ThrowExc(CSR_ERROR_FILE_SYSTEM, "Failed to get real path: " << target <<
+ " with errno: " << err);
+ }
+
+ return target;
+}
+
} // namespace anonymous
CsLogic::CsLogic(const std::shared_ptr<CsLoader> &loader,
StrSet canonicalized;
for (const auto &path : paths) {
- auto resolved = resolvePath(path);
- auto target = File::getPkgPath(resolved);
-
- if (::access(target.c_str(), R_OK) != 0) {
- const int err = errno;
- if (err == ENOENT)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target);
- else if (err == EACCES)
- ThrowExc(CSR_ERROR_PERMISSION_DENIED,
- "Perm denied to get real path: " << target);
- else
- ThrowExc(CSR_ERROR_FILE_SYSTEM, "Failed to get real path: " << target <<
- " with errno: " << err);
- }
+ auto target = canonicalizePath(path, true);
if (canonicalized.find(target) == canonicalized.end()) {
INFO("Insert to canonicalized list: " << target);
RawBuffer CsLogic::getDetected(const std::string &filepath)
{
- auto row = this->m_db->getDetectedByNameOnPath(File::getPkgPath(filepath));
+ auto row = this->m_db->getDetectedByNameOnPath(canonicalizePath(filepath, false));
if (row && !row->isIgnored)
return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
}
-RawBuffer CsLogic::getDetectedList(const StrSet &dirSet)
+RawBuffer CsLogic::getDetectedList(const StrSet &_dirSet)
{
+ StrSet dirSet;
+ for (const auto &dir : _dirSet)
+ dirSet.emplace(canonicalizePath(dir, false));
+
Db::RowShPtrs rows;
- std::for_each(dirSet.begin(), dirSet.end(),
- [this, &rows](const std::string & dir) {
- for (auto &row : this->m_db->getDetectedByNameOnDir(File::getPkgPath(dir)))
+ for (const auto &dir : dirSet) {
+ for (auto &row : this->m_db->getDetectedByNameOnDir(dir))
if (!row->isIgnored)
rows.emplace_back(std::move(row));
- });
+ }
if (rows.empty())
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
return BinaryQueue::Serialize(CSR_ERROR_NONE, rows).pop();
}
-// TODO: is this command needed?
RawBuffer CsLogic::getIgnored(const std::string &filepath)
{
- auto row = this->m_db->getDetectedByNameOnPath(File::getPkgPath(filepath));
+ auto row = this->m_db->getDetectedByNameOnPath(canonicalizePath(filepath, false));
if (row && row->isIgnored)
return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
}
-RawBuffer CsLogic::getIgnoredList(const StrSet &dirSet)
+RawBuffer CsLogic::getIgnoredList(const StrSet &_dirSet)
{
+ StrSet dirSet;
+ for (const auto &dir : _dirSet)
+ dirSet.emplace(canonicalizePath(dir, false));
+
Db::RowShPtrs rows;
- std::for_each(dirSet.begin(), dirSet.end(),
- [this, &rows](const std::string & dir) {
- for (auto &row : this->m_db->getDetectedByNameOnDir(File::getPkgPath(dir)))
+ for (const auto &dir : dirSet) {
+ for (auto &row : this->m_db->getDetectedByNameOnDir(dir))
if (row->isIgnored)
rows.emplace_back(std::move(row));
- });
+ }
if (rows.empty())
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();