Utils: Implement FilePath::removeRecursively

Sprinkle a few QTC_ASSERT to make sure we are in a known
context.

Cmake's FileApiReader uses this before moving directories
as QFile::rename does not do anything if the target exists.

Change-Id: I555f99e81a9fe7d93ae66145eeebfa9d5880bc51
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-28 15:26:44 +02:00
parent 5470385085
commit 5ead2afeeb
8 changed files with 47 additions and 2 deletions

View File

@@ -84,6 +84,7 @@ static DeviceFileHooks s_deviceHooks;
*/
bool FileUtils::removeRecursively(const FilePath &filePath, QString *error)
{
QTC_ASSERT(!filePath.needsDevice(), return false);
QFileInfo fileInfo = filePath.toFileInfo();
if (!fileInfo.exists() && !fileInfo.isSymLink())
return true;
@@ -1406,6 +1407,15 @@ bool FilePath::removeFile() const
return QFile::remove(path());
}
bool FilePath::removeRecursively() const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.removeRecursively, return false);
return s_deviceHooks.removeRecursively(*this);
}
return FileUtils::removeRecursively(*this);
}
bool FilePath::copyFile(const FilePath &target) const
{
if (needsDevice()) {