fix(LogFile): LogFile_STD (LogFileImpl) fails to recover from getting out of space #2084

This commit is contained in:
Alex Fabijanic
2022-05-28 20:50:29 -05:00
parent 9f7ccaf9f7
commit b52ec8cc47
2 changed files with 13 additions and 4 deletions

View File

@@ -43,6 +43,7 @@ private:
std::string _path; std::string _path;
mutable Poco::FileOutputStream _str; mutable Poco::FileOutputStream _str;
Timestamp _creationDate; Timestamp _creationDate;
UInt64 _size;
}; };

View File

@@ -22,9 +22,10 @@ namespace Poco {
LogFileImpl::LogFileImpl(const std::string& path): LogFileImpl::LogFileImpl(const std::string& path):
_path(path), _path(path),
_str(_path, std::ios::app) _str(_path, std::ios::app),
_size(static_cast<UInt64>(_str.tellp()))
{ {
if (sizeImpl() == 0) if (_size == 0)
_creationDate = File(path).getLastModified(); _creationDate = File(path).getLastModified();
else else
_creationDate = File(path).created(); _creationDate = File(path).created();
@@ -38,18 +39,25 @@ LogFileImpl::~LogFileImpl()
void LogFileImpl::writeImpl(const std::string& text, bool flush) void LogFileImpl::writeImpl(const std::string& text, bool flush)
{ {
std::streampos pos = _str.tellp();
_str << text; _str << text;
if (flush) if (flush)
_str << std::endl; _str << std::endl;
else else
_str << "\n"; _str << "\n";
if (!_str.good()) throw WriteFileException(_path); if (!_str.good())
{
_str.clear();
_str.seekp(pos);
throw WriteFileException(_path);
}
_size = static_cast<UInt64>(_str.tellp());
} }
UInt64 LogFileImpl::sizeImpl() const UInt64 LogFileImpl::sizeImpl() const
{ {
return (UInt64) _str.tellp(); return _size;
} }