Fix QDir::removeRecursively so it doesn't follow symlinks to directories.
Critical bug... Good thing I had backups of my $HOME. Change-Id: I43b3a80786c946b0aec797036c1164d436d521f8 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
parent
0443a51228
commit
8707c09fcd
@ -1502,7 +1502,7 @@ bool QDir::removeRecursively()
|
||||
di.next();
|
||||
const QFileInfo& fi = di.fileInfo();
|
||||
bool ok;
|
||||
if (fi.isDir())
|
||||
if (fi.isDir() && !fi.isSymLink())
|
||||
ok = QDir(di.filePath()).removeRecursively(); // recursive
|
||||
else
|
||||
ok = QFile::remove(di.filePath());
|
||||
|
@ -100,6 +100,7 @@ private slots:
|
||||
void removeRecursively_data();
|
||||
void removeRecursively();
|
||||
void removeRecursivelyFailure();
|
||||
void removeRecursivelySymlink();
|
||||
|
||||
void exists_data();
|
||||
void exists();
|
||||
@ -412,6 +413,31 @@ void tst_QDir::removeRecursivelyFailure()
|
||||
QVERIFY(!dir.exists());
|
||||
}
|
||||
|
||||
void tst_QDir::removeRecursivelySymlink()
|
||||
{
|
||||
#ifndef Q_NO_SYMLINKS
|
||||
const QString tmpdir = QDir::currentPath() + "/tmpdir/";
|
||||
QDir().mkpath(tmpdir);
|
||||
QDir currentDir;
|
||||
currentDir.mkdir("myDir");
|
||||
QFile("testfile").open(QIODevice::WriteOnly);
|
||||
const QString link = tmpdir + "linkToDir.lnk";
|
||||
const QString linkToFile = tmpdir + "linkToFile.lnk";
|
||||
#ifndef Q_NO_SYMLINKS_TO_DIRS
|
||||
QVERIFY(QFile::link("../myDir", link));
|
||||
QVERIFY(QFile::link("../testfile", linkToFile));
|
||||
#endif
|
||||
|
||||
QDir dir(tmpdir);
|
||||
QVERIFY(dir.removeRecursively());
|
||||
QVERIFY(QDir("myDir").exists()); // it didn't follow the symlink, good.
|
||||
QVERIFY(QFile::exists("testfile"));
|
||||
|
||||
currentDir.rmdir("myDir");
|
||||
QFile::remove("testfile");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QDir::exists_data()
|
||||
{
|
||||
QTest::addColumn<QString>("path");
|
||||
|
Loading…
Reference in New Issue
Block a user