mirror of
				https://github.com/pocoproject/poco.git
				synced 2025-11-03 19:40:37 +01:00 
			
		
		
		
	fix(LogFile): LogFile_STD (LogFileImpl) fails to recover from getting out of space #2084
This commit is contained in:
		@@ -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;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user