Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
5.9.5, 5.15.3, 6.9.0
-
None
-
-
92373d353 (dev), 09d44fdef (6.9), f3fc37146 (6.8), 510e94264 (tqtc/lts-6.5)
Description
Hi, I stumbled on the following bug:
When creating and committing a QSaveFile on a device that has no space left, the commit() will return true and empty the file.
Expected behavior : commit() should return false and keep the original file.
Tested on Ubuntu 18.04 and 22.04
Example code with steps to reproduce in linux :
#include <QCoreApplication> #include <QSaveFile> #include <QtDebug> /* * Reproduce: * - "mkdir -p /tmp/small && sudo mount -t tmpfs -o size=1m swap /tmp/small" * - run this program * - fill the disk : "dd if=/dev/zero count=10M bs=10 of=/tmp/small/bigfile" * - rerun this application; "/tmp/small/file.conf" will now be empty */ int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); QSaveFile saveFile("/tmp/small/file.conf"); QByteArray data(1000, 'a'); saveFile.open(QIODevice::WriteOnly); if(saveFile.write(data) != data.size()) { qWarning() << "failed to write to file: " << saveFile.errorString(); return 1; } if(!saveFile.commit()) { qWarning() << "failed to commit file: " << saveFile.errorString(); } return 0; }
Workaround:
replace the line "saveFile.commit();" with :
if(saveFile.flush()) { saveFile.commit(); } else { qWarning() << "Failed to flush file: " << saveFile.errorString(); }