diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-01-29 11:35:47 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-02-03 08:57:24 +0000 |
commit | e69e1e3719617d4fb48555c17e94af8e096f1647 (patch) | |
tree | 26a4b667019e0caed21cfbb7451774ce01ade78f | |
parent | 4bc2fbfcd7b71b42a3016123f8b9cf4ec4108225 (diff) |
Fix removeFileRecursion().
Neither symlinks to directories nor broken symlinks were handled
correctly (due to QFileInfo weirdness again).
Change-Id: I652e677643273c9d57f98d87b652483a870dcd0c
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
-rw-r--r-- | src/lib/corelib/tools/fileinfo.cpp | 7 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/symlink-removal/symlink-removal.qbs | 20 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 17 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 1 |
4 files changed, 43 insertions, 2 deletions
diff --git a/src/lib/corelib/tools/fileinfo.cpp b/src/lib/corelib/tools/fileinfo.cpp index 284f5323e..11f6f0c29 100644 --- a/src/lib/corelib/tools/fileinfo.cpp +++ b/src/lib/corelib/tools/fileinfo.cpp @@ -323,9 +323,12 @@ bool removeFileRecursion(const QFileInfo &f, QString *errorMessage) { if (!FileInfo::fileExists(f)) return true; - if (f.isDir()) { + if (f.isDir() && !f.isSymLink()) { const QDir dir(f.absoluteFilePath()); - foreach(const QFileInfo &fi, dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden)) + + // QDir::System is needed for broken symlinks. + foreach (const QFileInfo &fi, dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot + | QDir::Hidden | QDir::System)) removeFileRecursion(fi, errorMessage); QDir parent = f.absoluteDir(); if (!parent.rmdir(f.fileName())) { diff --git a/tests/auto/blackbox/testdata/symlink-removal/symlink-removal.qbs b/tests/auto/blackbox/testdata/symlink-removal/symlink-removal.qbs new file mode 100644 index 000000000..8e74149d1 --- /dev/null +++ b/tests/auto/blackbox/testdata/symlink-removal/symlink-removal.qbs @@ -0,0 +1,20 @@ +import qbs +import qbs.File + +Product { + type: "removal" + Transformer { + Artifact { + filePath: "dummy" + fileTags: product.type + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + File.remove(product.sourceDirectory + "/dir1"); + }; + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 266436a20..d1e3353ab 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -533,6 +533,23 @@ void TestBlackbox::resolve_project_dry_run() QVERIFY2(!QFile::exists(buildGraphPath), qPrintable(buildGraphPath)); } +void TestBlackbox::symlinkRemoval() +{ + if (HostOsInfo::isWindowsHost()) + SKIP_TEST("No symlink support on Windows"); + QDir::setCurrent(testDataDir + "/symlink-removal"); + QVERIFY(QDir::current().mkdir("dir1")); + QVERIFY(QDir::current().mkdir("dir2")); + QVERIFY(QFile::link("dir2", "dir1/broken-link")); + QVERIFY(QFile::link(QFileInfo("dir2").absoluteFilePath(), "dir1/valid-link-to-dir")); + QVERIFY(QFile::link(QFileInfo("symlink-removal.qbs").absoluteFilePath(), + "dir1/valid-link-to-file")); + QCOMPARE(runQbs(), 0); + QVERIFY(!QFile::exists("dir1")); + QVERIFY(QFile::exists("dir2")); + QVERIFY(QFile::exists("symlink-removal.qbs")); +} + void TestBlackbox::typeChange() { QDir::setCurrent(testDataDir + "/type-change"); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 2dd1215cf..dfa6ded06 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -146,6 +146,7 @@ private slots: void resolve_project(); void resolve_project_dry_run_data(); void resolve_project_dry_run(); + void symlinkRemoval(); void typeChange(); void usingsAsSoleInputsNonMultiplexed(); void clean(); |