diff options
author | Topi Reinio <topi.reinio@qt.io> | 2020-10-05 17:58:48 +0200 |
---|---|---|
committer | Topi Reinio <topi.reinio@qt.io> | 2020-10-10 13:53:16 +0200 |
commit | 9d1dd394191001cf2bc456cf73e702eeb7bac400 (patch) | |
tree | 6b43c4ece47045009dcf58e7f972ae241b9edd79 /src | |
parent | 07e5b38a61871dbbb76af4000b59fc9e7f4e44cc (diff) | |
download | qttools-9d1dd394191001cf2bc456cf73e702eeb7bac400.tar.gz |
qdoc: Stop removing content of the output directory
QDoc deleted the contents of the directory specified by -outputdir in
prepare phase - this was dangerous for users that do not expect that
behavior.
Instead of deleting, print out an error if the output directory is not
empty.
Fixes: QTBUG-87176
Change-Id: Iabefcc9733cf4c4b875fdd2bfd7f86f79d25349c
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qdoc/config.cpp | 30 | ||||
-rw-r--r-- | src/qdoc/config.h | 1 | ||||
-rw-r--r-- | src/qdoc/generator.cpp | 15 |
3 files changed, 8 insertions, 38 deletions
diff --git a/src/qdoc/config.cpp b/src/qdoc/config.cpp index 467f6ef09..57e71baf3 100644 --- a/src/qdoc/config.cpp +++ b/src/qdoc/config.cpp @@ -931,36 +931,6 @@ int Config::numParams(const QString &value) } /*! - Removes everything from \a dir. This function is recursive. - It doesn't remove \a dir itself, but if it was called - recursively, then the caller will remove \a dir. - */ -bool Config::removeDirContents(const QString &dir) -{ - QDir dirInfo(dir); - const QFileInfoList entries = dirInfo.entryInfoList(); - - bool ok = true; - - for (const auto &entry : entries) { - if (entry.isFile()) { - if (!dirInfo.remove(entry.fileName())) - ok = false; - } else if (entry.isDir()) { - if (entry.fileName() != QLatin1String(".") && entry.fileName() != QLatin1String("..")) { - if (removeDirContents(entry.absoluteFilePath())) { - if (!dirInfo.rmdir(entry.fileName())) - ok = false; - } else { - ok = false; - } - } - } - } - return ok; -} - -/*! Returns \c true if \a ch is a letter, number, '_', '.', '{', '}', or ','. */ diff --git a/src/qdoc/config.h b/src/qdoc/config.h index 691ec1e3f..44940dfa1 100644 --- a/src/qdoc/config.h +++ b/src/qdoc/config.h @@ -175,7 +175,6 @@ public: const QString &userFriendlySourceFilePath, const QString &targetDirPath); static int numParams(const QString &value); - static bool removeDirContents(const QString &dir); static void pushWorkingDir(const QString &dir); static QString popWorkingDir(); diff --git a/src/qdoc/generator.cpp b/src/qdoc/generator.cpp index 8b7fc9cb0..cea19c996 100644 --- a/src/qdoc/generator.cpp +++ b/src/qdoc/generator.cpp @@ -1851,14 +1851,14 @@ void Generator::initializeFormat() outSubdir_ = outDir_.mid(outDir_.lastIndexOf('/') + 1); } - QDir dirInfo; - if (dirInfo.exists(outDir_)) { + QDir outputDir(outDir_); + if (outputDir.exists()) { if (!config.generating() && Generator::useOutputSubdirs()) { - if (!Config::removeDirContents(outDir_)) + if (!outputDir.isEmpty()) config.lastLocation().error( - QStringLiteral("Cannot empty output directory '%1'").arg(outDir_)); + QStringLiteral("Output directory '%1' exists but is not empty").arg(outDir_)); } - } else if (!dirInfo.mkpath(outDir_)) { + } else if (!outputDir.mkpath(QStringLiteral("."))) { config.lastLocation().fatal( QStringLiteral("Cannot create output directory '%1'").arg(outDir_)); } @@ -1867,9 +1867,10 @@ void Generator::initializeFormat() if (config.preparing()) return; - if (!dirInfo.exists(outDir_ + "/images") && !dirInfo.mkdir(outDir_ + "/images")) + const QLatin1String imagesDir("images"); + if (!outputDir.exists(imagesDir) && !outputDir.mkdir(imagesDir)) config.lastLocation().fatal( - QStringLiteral("Cannot create images directory '%1'").arg(outDir_ + "/images")); + QStringLiteral("Cannot create images directory '%1'").arg(outputDir.filePath(imagesDir))); copyTemplateFiles(format() + Config::dot + CONFIG_STYLESHEETS, "style"); copyTemplateFiles(format() + Config::dot + CONFIG_SCRIPTS, "scripts"); |