diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-02-16 13:58:55 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-04-07 20:26:02 +0000 |
commit | 23d08ce2edab09562ad283dac5d46c09efec63ca (patch) | |
tree | e6d55a72fabf16cdbc8babb01ab8b951164ed5a3 /tests/auto/corelib/io/qdir | |
parent | 49163ca689562a4a000490fb137e5c9533684471 (diff) |
Fix QDir::mkpath() when the path contains "symlink/../"
It is incorrect to collapse a "symlink/.." segment because the parent
directory of the symlink's target may not be the directory where the
symlink itself is located.
[ChangeLog][QtCore][QDir] Fixed a bug that caused QDir::mkpath() to
create the wrong directory if the requested path contained a symbolic
link and "../".
Change-Id: Iaddbecfbba5441c8b2e4fffd14a3e367730a1e24
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto/corelib/io/qdir')
-rw-r--r-- | tests/auto/corelib/io/qdir/tst_qdir.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 330ff9312d..946620d61f 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2017 Intel Corporation. ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** @@ -101,6 +102,7 @@ private slots: void mkdirRmdir_data(); void mkdirRmdir(); + void mkdirOnSymlink(); void makedirReturnCode(); @@ -387,6 +389,56 @@ void tst_QDir::mkdirRmdir() QVERIFY(!fi.exists()); } +void tst_QDir::mkdirOnSymlink() +{ +#ifndef Q_OS_UNIX + QSKIP("Test only valid on an OS that supports symlinks"); +#else + // Create the structure: + // . + // ├── symlink -> two/three + // └── two + // └── three + // so when we mkdir("symlink/../four/five"), we end up with: + // . + // ├── symlink -> two/three + // └── two + // ├── four + // │ └── five + // └── three + + QDir dir; + struct Clean { + QDir &dir; + Clean(QDir &dir) : dir(dir) {} + ~Clean() { doClean(); } + void doClean() { + dir.rmpath("two/three"); + dir.rmpath("two/four/five"); + // in case the test fails, don't leave junk behind + dir.rmpath("four/five"); + QFile::remove("symlink"); + } + }; + Clean clean(dir); + clean.doClean(); + + // create our structure: + dir.mkpath("two/three"); + ::symlink("two/three", "symlink"); + + // try it: + QString path = "symlink/../four/five"; + QVERIFY(dir.mkpath(path)); + QFileInfo fi(path); + QVERIFY2(fi.exists() && fi.isDir(), msgDoesNotExist(path).constData()); + + path = "two/four/five"; + fi.setFile(path); + QVERIFY2(fi.exists() && fi.isDir(), msgDoesNotExist(path).constData()); +#endif +} + void tst_QDir::makedirReturnCode() { QString dirName = QString::fromLatin1("makedirReturnCode"); |