Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/nntpchan-daemon/libnntpchan/storage.cpp

48 lines
933 B
C++
Raw Normal View History

2017-10-11 18:48:27 +05:00
#include <nntpchan/storage.hpp>
#include <nntpchan/sanitize.hpp>
#include <sstream>
namespace nntpchan
{
ArticleStorage::ArticleStorage()
{
}
ArticleStorage::ArticleStorage(const fs::path & fpath) {
SetPath(fpath);
}
ArticleStorage::~ArticleStorage()
{
}
void ArticleStorage::SetPath(const fs::path & fpath)
{
basedir = fpath;
fs::create_directories(basedir);
}
bool ArticleStorage::Accept(const std::string& msgid)
{
if (!IsValidMessageID(msgid)) return false;
auto p = MessagePath(msgid);
return !fs::exists(p);
}
fs::path ArticleStorage::MessagePath(const std::string & msgid)
{
return basedir / msgid;
}
FileHandle_ptr ArticleStorage::OpenRead(const std::string & msgid)
{
return OpenFile(MessagePath(msgid), eRead);
}
FileHandle_ptr ArticleStorage::OpenWrite(const std::string & msgid)
{
return OpenFile(MessagePath(msgid), eWrite);
}
}