45
LogFileImpl::LogFileImpl(const std::string& path): _path(path)
47
_hFile = CreateFileA(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
48
if (_hFile == INVALID_HANDLE_VALUE) throw OpenFileException(path);
45
LogFileImpl::LogFileImpl(const std::string& path): _path(path), _hFile(INVALID_HANDLE_VALUE)
51
_creationDate = file.getLastModified();
53
_creationDate = file.created();
58
LogFileImpl::~LogFileImpl()
64
void LogFileImpl::writeImpl(const std::string& text)
66
if (INVALID_HANDLE_VALUE == _hFile) createFile();
69
BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL);
70
if (!res) throw WriteFileException(_path);
71
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
72
if (!res) throw WriteFileException(_path);
73
res = FlushFileBuffers(_hFile);
74
if (!res) throw WriteFileException(_path);
78
UInt64 LogFileImpl::sizeImpl() const
80
if (INVALID_HANDLE_VALUE == _hFile)
83
if (file.exists()) return file.getSize();
89
li.LowPart = SetFilePointer(_hFile, 0, &li.HighPart, FILE_CURRENT);
94
Timestamp LogFileImpl::creationDateImpl() const
100
const std::string& LogFileImpl::pathImpl() const
106
void LogFileImpl::createFile()
108
_hFile = CreateFileA(_path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
109
if (_hFile == INVALID_HANDLE_VALUE) throw OpenFileException(_path);
49
110
SetFilePointer(_hFile, 0, 0, FILE_END);
50
111
// There seems to be a strange "optimization" in the Windows NTFS
51
112
// filesystem that causes it to reuse directory entries of deleted
61
122
// modification date as a reference when the
63
124
if (sizeImpl() == 0)
64
_creationDate = File(path).getLastModified();
125
_creationDate = File(_path).getLastModified();
66
_creationDate = File(path).created();
70
LogFileImpl::~LogFileImpl()
76
void LogFileImpl::writeImpl(const std::string& text)
79
BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL);
80
if (!res) throw WriteFileException(_path);
81
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
82
if (!res) throw WriteFileException(_path);
83
res = FlushFileBuffers(_hFile);
84
if (!res) throw WriteFileException(_path);
88
UInt64 LogFileImpl::sizeImpl() const
92
li.LowPart = SetFilePointer(_hFile, 0, &li.HighPart, FILE_CURRENT);
97
Timestamp LogFileImpl::creationDateImpl() const
103
const std::string& LogFileImpl::pathImpl() const
127
_creationDate = File(_path).created();
109
130
} // namespace Poco