mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-19 00:46:03 +01:00
fix(LogFile): LogFile_STD (LogFileImpl) fails to recover from getting out of space #2084
This commit is contained in:
parent
9f7ccaf9f7
commit
b52ec8cc47
@ -43,6 +43,7 @@ private:
|
||||
std::string _path;
|
||||
mutable Poco::FileOutputStream _str;
|
||||
Timestamp _creationDate;
|
||||
UInt64 _size;
|
||||
};
|
||||
|
||||
|
||||
|
@ -22,9 +22,10 @@ namespace Poco {
|
||||
|
||||
LogFileImpl::LogFileImpl(const std::string& 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();
|
||||
else
|
||||
_creationDate = File(path).created();
|
||||
@ -38,18 +39,25 @@ LogFileImpl::~LogFileImpl()
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text, bool flush)
|
||||
{
|
||||
std::streampos pos = _str.tellp();
|
||||
_str << text;
|
||||
if (flush)
|
||||
_str << std::endl;
|
||||
else
|
||||
_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
|
||||
{
|
||||
return (UInt64) _str.tellp();
|
||||
return _size;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user