Fix cd(), cdUp() QDir member functions docs regarding nonreadable dirs

The documentation implies that cd() and cdUp() functions return false if
the new directory is not readable, but that is not the case. It is an
obvious mistake in the documentation, because cd'ing into a nonreadable
directory is perfectly valid.

Provided also with a test to verify that cd() actually returns true with
nonreadable directories.

Change-Id: I4aa3e859b35c64266df510a203574e3701aea77c
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Bartosz Brachaczek 2013-12-29 04:01:27 +01:00 committed by The Qt Project
parent 446f9f2812
commit 7ffce3fb0b
2 changed files with 21 additions and 2 deletions

View File

@ -855,7 +855,7 @@ QString QDir::fromNativeSeparators(const QString &pathName)
/*!
Changes the QDir's directory to \a dirName.
Returns \c true if the new directory exists and is readable;
Returns \c true if the new directory exists;
otherwise returns \c false. Note that the logical cd() operation is
not performed if the new directory does not exist.
@ -923,7 +923,7 @@ bool QDir::cd(const QString &dirName)
Changes directory by moving one directory up from the QDir's
current directory.
Returns \c true if the new directory exists and is readable;
Returns \c true if the new directory exists;
otherwise returns \c false. Note that the logical cdUp() operation is
not performed if the new directory does not exist.

View File

@ -193,6 +193,8 @@ private slots:
void isReadable();
void cdNonreadable();
void cdBelowRoot();
private:
@ -1990,6 +1992,23 @@ void tst_QDir::isReadable()
#endif
}
void tst_QDir::cdNonreadable()
{
#ifdef Q_OS_UNIX
if (::getuid() == 0)
QSKIP("Running this test as root doesn't make sense");
QDir dir;
QVERIFY(dir.mkdir("nonreadabledir2"));
QVERIFY(0 == ::chmod("nonreadabledir2", S_IWUSR | S_IXUSR));
QVERIFY(dir.cd("nonreadabledir2"));
QVERIFY(!dir.isReadable());
QVERIFY(dir.cd(".."));
QVERIFY(0 == ::chmod("nonreadabledir2", S_IRUSR | S_IWUSR | S_IXUSR));
QVERIFY(dir.rmdir("nonreadabledir2"));
#endif
}
void tst_QDir::cdBelowRoot()
{
#if defined (Q_OS_UNIX)