QTemporaryDir: Remove directories on failure

When creating a temporary directory but failing to set its permissions,
we need to remove the directory we created to avoid leaving 256 empty,
unused directories in the destination folder.

This happens on Android if you try creating a QTemporaryDir in the
download path on the sdcard.

Task-number: QTBUG-43352
Change-Id: Ic88fb7572f1abd65e5c7d8882b59c95f4b22ed72
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2015-01-20 09:34:42 +01:00 committed by Jani Heikkinen
parent 9e4ef3539a
commit 508b1fa173
2 changed files with 18 additions and 1 deletions

View File

@ -128,8 +128,11 @@ static char *q_mkdtemp(char *templateName)
QFile::ReadOwner | QFile::ReadOwner |
QFile::WriteOwner | QFile::WriteOwner |
QFile::ExeOwner, error); QFile::ExeOwner, error);
if (error.error() != 0) if (error.error() != 0) {
if (!QFileSystemEngine::removeDirectory(fileSystemEntry, false))
qWarning() << "Unable to remove unused directory" << templateNameStr;
continue; continue;
}
return templateName; return templateName;
} }
} }

View File

@ -70,6 +70,8 @@ private slots:
void QTBUG_4796_data(); void QTBUG_4796_data();
void QTBUG_4796(); void QTBUG_4796();
void QTBUG43352_failedSetPermissions();
public: public:
}; };
@ -419,5 +421,17 @@ void tst_QTemporaryDir::QTBUG_4796() // unicode support
cleaner.reset(); cleaner.reset();
} }
void tst_QTemporaryDir::QTBUG43352_failedSetPermissions()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + QStringLiteral("/");
int count = QDir(path).entryList().size();
{
QTemporaryDir dir(path);
}
QCOMPARE(QDir(path).entryList().size(), count);
}
QTEST_MAIN(tst_QTemporaryDir) QTEST_MAIN(tst_QTemporaryDir)
#include "tst_qtemporarydir.moc" #include "tst_qtemporarydir.moc"