forked from qt-creator/qt-creator
Utils: Merge FileUtils::removeRecursively() into FilePath
This simplify the interface by removing a possibly wrong choice ensures it works also on remote paths. Change-Id: I01e198958900a91b99dcf2dbb491a593485493ba Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -197,7 +197,7 @@ bool BuildableHelperLibrary::copyFiles(const QString &sourcePath,
|
||||
QString *errorMessage)
|
||||
{
|
||||
// try remove the directory
|
||||
if (!FileUtils::removeRecursively(FilePath::fromString(targetDirectory), errorMessage))
|
||||
if (!FilePath::fromString(targetDirectory).removeRecursively(errorMessage))
|
||||
return false;
|
||||
if (!QDir().mkpath(targetDirectory)) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "The target directory %1 could not be created.").arg(targetDirectory);
|
||||
|
@@ -76,14 +76,7 @@ static DeviceFileHooks s_deviceHooks;
|
||||
|
||||
*/
|
||||
|
||||
/*!
|
||||
Removes the directory \a filePath and its subdirectories recursively.
|
||||
|
||||
\note The \a error parameter is optional.
|
||||
|
||||
Returns whether the operation succeeded.
|
||||
*/
|
||||
bool FileUtils::removeRecursively(const FilePath &filePath, QString *error)
|
||||
static bool removeRecursivelyLocal(const FilePath &filePath, QString *error)
|
||||
{
|
||||
QTC_ASSERT(!filePath.needsDevice(), return false);
|
||||
QFileInfo fileInfo = filePath.toFileInfo();
|
||||
@@ -111,7 +104,7 @@ bool FileUtils::removeRecursively(const FilePath &filePath, QString *error)
|
||||
const QStringList fileNames = dir.entryList(
|
||||
QDir::Files | QDir::Hidden | QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (const QString &fileName : fileNames) {
|
||||
if (!removeRecursively(filePath / fileName, error))
|
||||
if (!removeRecursivelyLocal(filePath / fileName, error))
|
||||
return false;
|
||||
}
|
||||
if (!QDir::root().rmdir(dir.path())) {
|
||||
@@ -1443,13 +1436,20 @@ bool FilePath::removeFile() const
|
||||
return QFile::remove(path());
|
||||
}
|
||||
|
||||
bool FilePath::removeRecursively() const
|
||||
/*!
|
||||
Removes the directory this filePath refers too and its subdirectories recursively.
|
||||
|
||||
\note The \a error parameter is optional.
|
||||
|
||||
Returns whether the operation succeeded.
|
||||
*/
|
||||
bool FilePath::removeRecursively(QString *error) const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.removeRecursively, return false);
|
||||
return s_deviceHooks.removeRecursively(*this);
|
||||
}
|
||||
return FileUtils::removeRecursively(*this);
|
||||
return removeRecursivelyLocal(*this, error);
|
||||
}
|
||||
|
||||
bool FilePath::copyFile(const FilePath &target) const
|
||||
|
@@ -175,7 +175,7 @@ public:
|
||||
QDateTime lastModified() const;
|
||||
QFile::Permissions permissions() const;
|
||||
bool removeFile() const;
|
||||
bool removeRecursively() const;
|
||||
bool removeRecursively(QString *error = nullptr) const;
|
||||
bool copyFile(const FilePath &target) const;
|
||||
bool renameFile(const FilePath &target) const;
|
||||
|
||||
@@ -242,7 +242,6 @@ public:
|
||||
};
|
||||
#endif // QT_GUI_LIB
|
||||
|
||||
static bool removeRecursively(const FilePath &filePath, QString *error = nullptr);
|
||||
static bool copyRecursively(const FilePath &srcFilePath,
|
||||
const FilePath &tgtFilePath,
|
||||
QString *error = nullptr);
|
||||
|
@@ -137,7 +137,7 @@ void AndroidPackageInstallationStep::doRun()
|
||||
FilePath androidDir = FilePath::fromString(dir);
|
||||
if (!dir.isEmpty() && androidDir.exists()) {
|
||||
emit addOutput(tr("Removing directory %1").arg(dir), OutputFormat::NormalMessage);
|
||||
if (!FileUtils::removeRecursively(androidDir, &error)) {
|
||||
if (!androidDir.removeRecursively(&error)) {
|
||||
emit addOutput(error, OutputFormat::Stderr);
|
||||
TaskHub::addTask(BuildSystemTask(Task::Error, error));
|
||||
emit finished(false);
|
||||
|
@@ -47,7 +47,7 @@ VirtualFileSystemOverlay::VirtualFileSystemOverlay(const QString &rootPattern)
|
||||
|
||||
void VirtualFileSystemOverlay::update()
|
||||
{
|
||||
Utils::FileUtils::removeRecursively(overlayFilePath());
|
||||
overlayFilePath().removeRecursively();
|
||||
QFile overlayFile(m_overlayFilePath.toString());
|
||||
if (!overlayFile.open(QFile::ReadWrite))
|
||||
return;
|
||||
@@ -61,8 +61,7 @@ void VirtualFileSystemOverlay::update()
|
||||
documentRoots[doc->filePath().absolutePath()] << doc;
|
||||
AutoSavedPath saved = m_saved.take(document);
|
||||
if (saved.revision != document->document()->revision()) {
|
||||
if (saved.path.exists())
|
||||
Utils::FileUtils::removeRecursively(saved.path);
|
||||
saved.path.removeRecursively();
|
||||
saved.revision = document->document()->revision();
|
||||
QString error;
|
||||
saved.path = Utils::FilePath::fromString(m_root.path())
|
||||
@@ -79,7 +78,7 @@ void VirtualFileSystemOverlay::update()
|
||||
|
||||
for (const AutoSavedPath &path : qAsConst(m_saved)) {
|
||||
QString error;
|
||||
if (!Utils::FileUtils::removeRecursively(path.path, &error))
|
||||
if (!path.path.removeRecursively(&error))
|
||||
qCDebug(LOG) << error;
|
||||
}
|
||||
m_saved = newSaved;
|
||||
|
@@ -513,7 +513,7 @@ void CMakeBuildSystem::clearCMakeCache()
|
||||
|
||||
stopParsingAndClearState();
|
||||
|
||||
const QList<FilePath> pathsToDelete = {
|
||||
const FilePath pathsToDelete[] = {
|
||||
m_parameters.buildDirectory / "CMakeCache.txt",
|
||||
m_parameters.buildDirectory / "CMakeCache.txt.prev",
|
||||
m_parameters.buildDirectory / "CMakeFiles",
|
||||
@@ -521,10 +521,8 @@ void CMakeBuildSystem::clearCMakeCache()
|
||||
m_parameters.buildDirectory / ".cmake/api/v1/reply.prev"
|
||||
};
|
||||
|
||||
for (const FilePath &path : pathsToDelete) {
|
||||
if (path.exists())
|
||||
FileUtils::removeRecursively(path);
|
||||
}
|
||||
for (const FilePath &path : pathsToDelete)
|
||||
path.removeRecursively();
|
||||
}
|
||||
|
||||
std::unique_ptr<CMakeProjectNode> CMakeBuildSystem::generateProjectTree(
|
||||
|
@@ -100,7 +100,7 @@ void CppToolsPlugin::initTestCase()
|
||||
|
||||
void CppToolsPlugin::cleanupTestCase()
|
||||
{
|
||||
Utils::FileUtils::removeRecursively(Utils::FilePath::fromString(baseTestDir()));
|
||||
Utils::FilePath::fromString(baseTestDir()).removeRecursively();
|
||||
CppFileSettings *fs = fileSettings();
|
||||
fs->headerSearchPaths.removeLast();
|
||||
fs->headerSearchPaths.removeLast();
|
||||
|
Reference in New Issue
Block a user