[proxy,module] always check path exists for dyn-channel-dump

This commit is contained in:
Armin Novak 2023-06-28 16:57:03 +02:00 committed by akallabeth
parent ceb346241b
commit 1dfe7878f6

View File

@ -120,20 +120,8 @@ class ChannelData
return enabled; return enabled;
} }
std::filesystem::path filepath(const std::string& channel, bool back, uint64_t count) const bool ensure_path_exists()
{ {
auto name = idstr(channel, back);
char cstr[32] = {};
_snprintf(cstr, sizeof(cstr), "%016" PRIx64 "-", count);
auto path = _base / cstr;
path += name;
path += ".dump";
return path;
}
bool create()
{
if (!std::filesystem::exists(_base)) if (!std::filesystem::exists(_base))
{ {
if (!std::filesystem::create_directories(_base)) if (!std::filesystem::create_directories(_base))
@ -147,6 +135,13 @@ class ChannelData
WLog_ERR(TAG, "dump path %s is not a directory", _base.c_str()); WLog_ERR(TAG, "dump path %s is not a directory", _base.c_str());
return false; return false;
} }
return true;
}
bool create()
{
if (!ensure_path_exists())
return false;
if (_channels_to_dump.empty()) if (_channels_to_dump.empty())
{ {
@ -163,6 +158,17 @@ class ChannelData
} }
private: private:
std::filesystem::path filepath(const std::string& channel, bool back, uint64_t count) const
{
auto name = idstr(channel, back);
char cstr[32] = {};
_snprintf(cstr, sizeof(cstr), "%016" PRIx64 "-", count);
auto path = _base / cstr;
path += name;
path += ".dump";
return path;
}
std::string idstr(const std::string& name, bool back) const std::string idstr(const std::string& name, bool back) const
{ {
std::stringstream ss; std::stringstream ss;
@ -302,6 +308,9 @@ static BOOL dump_dyn_channel_intercept(proxyPlugin* plugin, proxyData* pdata, vo
return FALSE; return FALSE;
} }
if (!cdata->ensure_path_exists())
return FALSE;
auto stream = cdata->stream(data->name, data->isBackData); auto stream = cdata->stream(data->name, data->isBackData);
auto buffer = reinterpret_cast<const char*>(Stream_ConstBuffer(data->data)); auto buffer = reinterpret_cast<const char*>(Stream_ConstBuffer(data->data));
if (!stream.is_open() || !stream.good()) if (!stream.is_open() || !stream.good())