QFile::rename: fix the error message if renaming a file by copy fails

The QFile out variable cannot be open because if out.open() succeeded,
we could never reach this line. Instead, we want to capture *why* either
the source or the destination failed to open.

Task-number: QTBUG-66445
Change-Id: I940917d6763842499b18fffd15142f231bf34a47
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
This commit is contained in:
Thiago Macieira 2018-02-17 10:06:42 -08:00
parent 79493a3ee1
commit d3b6ef6ccf

View File

@ -676,8 +676,11 @@ QFile::rename(const QString &newName)
return !error;
}
close();
d->setError(QFile::RenameError,
tr("Cannot open destination file: %1").arg(out.errorString()));
} else {
d->setError(QFile::RenameError, errorString());
}
d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString());
}
return false;
}