Skip to content

Commit

Permalink
SKA-504: throw for nonexistent files (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
VKyllianAubry authored and GitHub Enterprise committed May 17, 2024
1 parent 98530b6 commit 42a0090
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions advalues/adapter/AdManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "AdManager.hpp"

#include <algorithm>
#include <filesystem>
#include <sys/inotify.h>

#include "../../util/Exceptions.hpp"
Expand Down Expand Up @@ -46,6 +47,11 @@ void AdManager::InitAdaptersFromConfigFile(const YAML::Node& configFile,
std::unique_ptr<PubSubSpec> subDataSpec, pubDataSpec;
std::string publisherName, subscriberName;

if (!std::filesystem::exists(fileValuesYaml.path + fileValuesYaml.fileName))
{
throw std::runtime_error("file " + fileValuesYaml.path + fileValuesYaml.fileName + " does not exist");
}

// Manage topic_subscribe
if (!fileValuesYaml.topic_subscribe.empty())
{
Expand Down
7 changes: 7 additions & 0 deletions chardev/adapter/ChardevManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "ChardevManager.hpp"

#include <filesystem>

#include "../../util/FileHelper.hpp"
#include "../../util/Exceptions.hpp"

Expand Down Expand Up @@ -71,6 +73,11 @@ void ChardevManager::InitAdaptersFromConfigFile(const YAML::Node& configFile,
for (auto chardevYaml : chardevYAMLConfigs)
{
const std::string pathToFile = chardevYaml.path;

if (!std::filesystem::exists(pathToFile))
{
throw std::runtime_error("file " + pathToFile + " does not exist");
}

std::string pathToFile_ = pathToFile;
for(std::size_t i = 0; i < pathToFile_.size(); ++i)
Expand Down
6 changes: 6 additions & 0 deletions gpio/adapter/GpioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "GpioManager.hpp"

#include <thread>
#include <filesystem>
#include <sys/ioctl.h>
#include <linux/gpio.h>

Expand Down Expand Up @@ -71,6 +72,11 @@ void GpioManager::InitAdaptersFromConfigFile(const YAML::Node& configFile,
std::vector<Util::DataYAMLConfig> gpioYAMLConfigs;
GetYamlConfig(chipNode, gpioYAMLConfigs, chipPath);

if (!std::filesystem::exists(chipPath))
{
throw std::runtime_error("GPIO chip " + chipPath + " does not exist");
}

const auto chipName = chipPath.substr(chipPath.find_last_of('/') + 1);

auto ioc = std::make_unique<Ioc>();
Expand Down

0 comments on commit 42a0090

Please sign in to comment.