Commit 07c3a370 authored by Ivan Donchevskii's avatar Ivan Donchevskii

Utils: improve failed file saving behavior

Remove temporary files left after fail.
Set error string for locked file.

Task-number: QTCREATORBUG-15449
Change-Id: Ibc8b01a4ea47870c29493a69718db929070ac13f
Reviewed-by: Oswald Buddenhagen's avatarOswald Buddenhagen <oswald.buddenhagen@qt.io>
parent 1607a34a
......@@ -437,8 +437,13 @@ bool FileSaverBase::write(const QByteArray &bytes)
bool FileSaverBase::setResult(bool ok)
{
if (!ok && !m_hasError) {
m_errorString = tr("Cannot write file %1. Disk full?").arg(
QDir::toNativeSeparators(m_fileName));
if (!m_file->errorString().isEmpty()) {
m_errorString = tr("Cannot write file %1: %2").arg(
QDir::toNativeSeparators(m_fileName), m_file->errorString());
} else {
m_errorString = tr("Cannot write file %1. Disk full?").arg(
QDir::toNativeSeparators(m_fileName));
}
m_hasError = true;
}
return ok;
......
......@@ -113,10 +113,19 @@ bool SaveFile::commit()
QString finalFileName
= FileUtils::resolveSymlinks(FileName::fromString(m_finalFileName)).toString();
QString bakname = finalFileName + QLatin1Char('~');
QFile::remove(bakname); // Kill old backup
QFile::rename(finalFileName, bakname); // Backup current file
if (QFile::exists(finalFileName)) {
QFile::remove(bakname); // Kill old backup
// Try to back up current file
if (!QFile::rename(finalFileName, bakname)) {
remove();
setErrorString(tr("File might be locked."));
return false;
}
}
if (!rename(finalFileName)) { // Replace current file
QFile::rename(bakname, finalFileName); // Rollback to current file
remove();
return false;
}
if (!m_backup)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment