CSVSink throws if `m_directory` not provided
What
Currently, CSVSink
does not appear to absolutely require that the field "directory"
be defined in the datasinks
configuration:
void CSVSink::setConfiguration(const nlohmann::json& config)
{
for (const auto &kv : config.items())
{
if(kv.key()=="directory")
{
m_directory=kv.value();
}
}
}
And m_directory
is initialized as the empty string (""
).
Later on, in CSVSink::startMeasurement
the output filename is formed as:
std::string fileName = m_directory+"/"+m_measurement+".csv";
This will fail if the "directory"
field is not provided in the "datasinks"
configuration since only the root
user has access to /
. That is, the default filename is /foo.csv
which cannot be accessed by a non-root
user.
Suggested Action
"directory"
a required field
1. Make By making the "directory"
field required, then in CSVSink::setConfiguration
we can check that the directory is readable/writeable and valid. If the "directory"
field is not provided in the configuration, then the code should throw an exception letting the user know that the CSVSink
configuration does not respect the expected schema.
m_directory
default to a well-known valid directory
2. Make If the "directory"
field in the JSON configuration for the CSVSink
class is going to not be required, then it should be safe to not provide it. By defining a "default" directory that is guaranteed to always be readable/writeable by the user this will work. For example, by setting m_directory = "./"
by default then things should be OK and the output files will by default be written to in the caller's current working directory.