mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 06:25:33 +08:00
refs #782 Extended error information when data cache fails to write.
This commit is contained in:
committed by
Klaus Basan
parent
6a5444590e
commit
0b07088639
@@ -18,6 +18,7 @@
|
||||
|
||||
#if defined(Q_OS_POSIX)
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#elif defined(Q_OS_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
@@ -90,13 +91,27 @@ namespace BlackMisc
|
||||
void CAtomicFile::replaceOriginal()
|
||||
{
|
||||
auto result = ::rename(qPrintable(fileName()), qPrintable(m_originalFilename));
|
||||
if (result < 0) { m_renameError = true; }
|
||||
if (result < 0)
|
||||
{
|
||||
m_renameError = true;
|
||||
char s[1024] {};
|
||||
auto x = strerror_r(errno, s, sizeof(s));
|
||||
setErrorString(QString::fromLocal8Bit(s));
|
||||
static_assert(std::is_same<decltype(x), int>::value, "Non-standard signature of POSIX function strerror_r, check documentation.");
|
||||
}
|
||||
}
|
||||
#elif defined(Q_OS_WIN32)
|
||||
void CAtomicFile::replaceOriginal()
|
||||
{
|
||||
auto result = MoveFileExA(qPrintable(fileName()), qPrintable(m_originalFilename), MOVEFILE_REPLACE_EXISTING);
|
||||
if (! result) { m_renameError = true; }
|
||||
if (! result)
|
||||
{
|
||||
m_renameError = true;
|
||||
wchar_t *s = nullptr;
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), 0, reinterpret_cast<LPWSTR>(&s), 0, nullptr);
|
||||
setErrorString(QString::fromWCharArray(s));
|
||||
LocalFree(reinterpret_cast<HLOCAL>(s));
|
||||
}
|
||||
}
|
||||
#else
|
||||
void CAtomicFile::replaceOriginal()
|
||||
|
||||
@@ -479,7 +479,7 @@ namespace BlackMisc
|
||||
|
||||
if (! revisionFile.checkedClose())
|
||||
{
|
||||
CLogMessage(this).error("Failed to write to %1: %2") << revisionFile.fileName() << revisionFile.errorString();
|
||||
CLogMessage(this).error("Failed to write to %1: %2 (%3 %4)") << revisionFile.fileName() << revisionFile.errorString() << QThread::currentThread()->objectName() << Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ namespace BlackMisc
|
||||
|
||||
if (!(revisionFile.seek(0) && revisionFile.resize(0) && revisionFile.write(QJsonDocument(json).toJson()) && revisionFile.checkedClose()))
|
||||
{
|
||||
CLogMessage(this).error("Failed to write to %1: %2") << revisionFile.fileName() << revisionFile.errorString();
|
||||
CLogMessage(this).error("Failed to write to %1: %2 (%3 %4)") << revisionFile.fileName() << revisionFile.errorString() << QThread::currentThread()->objectName() << Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
m_lockFile.unlock();
|
||||
@@ -776,7 +776,7 @@ namespace BlackMisc
|
||||
json.insert("uuid", uuid.toString());
|
||||
if (!(file.seek(0) && file.resize(0) && file.write(QJsonDocument(json).toJson()) && file.checkedClose()))
|
||||
{
|
||||
CLogMessage(this).error("Failed to write to session file %1: %2") << m_filename << file.errorString();
|
||||
CLogMessage(this).error("Failed to write to session file %1: %2 (%3 %4)") << m_filename << file.errorString() << QThread::currentThread()->objectName() << Q_FUNC_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user