From 16829f0bae1a0ea24a31bc3101ad33ddf55aa261 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Thu, 22 Dec 2016 11:31:12 +0100 Subject: QImageWriter: Explain slightly strange looking logic in canWrite Change-Id: Ic0fa4783351144ad8739669f1655b2fb0639a43d Reviewed-by: Eirik Aavitsland --- src/gui/image/qimagewriter.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/gui/image/qimagewriter.cpp') diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index f3af2738af..fd2c51ebd8 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -705,6 +705,11 @@ bool QImageWriter::canWrite() const if (QFile *file = qobject_cast(d->device)) { const bool remove = !file->isOpen() && !file->exists(); const bool result = d->canWriteHelper(); + + // This looks strange (why remove if it doesn't exist?) but the issue + // here is that canWriteHelper will create the file in the process of + // checking if the write can succeed. If it subsequently fails, we + // should remove that empty file. if (!result && remove) file->remove(); return result; -- cgit v1.2.3