canonicalFilePath: treat ENOTDIR as a case of file not existing
There is no such file, if one of the "directory" components of its path is not, in fact, a directory. Added a test for non-existent file (specified to give empty canonical file path) as well as a test for a file in a sub-directory of a known file. The former incidentally tests for QTBUG-29402, fixed long ago. Change-Id: I60b80acc0f99f0a88cdb1c4d191af7384f3a31c5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ed79462d99
commit
f69a5857d1
@ -774,7 +774,7 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
|
||||
QString canonicalPath = QDir::cleanPath(QFile::decodeName(ret));
|
||||
free(ret);
|
||||
return QFileSystemEntry(canonicalPath);
|
||||
} else if (errno == ENOENT) { // file doesn't exist
|
||||
} else if (errno == ENOENT || errno == ENOTDIR) { // file doesn't exist
|
||||
data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
|
||||
data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute);
|
||||
return QFileSystemEntry();
|
||||
|
@ -630,6 +630,16 @@ void tst_QFileInfo::canonicalFilePath()
|
||||
info.canonicalFilePath();
|
||||
|
||||
#if defined(Q_OS_UNIX)
|
||||
// If this file exists, you can't log in to run this test ...
|
||||
const QString notExtantPath(QStringLiteral("/etc/nologin"));
|
||||
QFileInfo notExtant(notExtantPath);
|
||||
QCOMPARE(notExtant.canonicalFilePath(), QString());
|
||||
|
||||
// A path with a non-directory as a directory component also doesn't exist:
|
||||
const QString badDirPath(QStringLiteral("/dev/null/sub/dir/n'existe.pas"));
|
||||
QFileInfo badDir(badDirPath);
|
||||
QCOMPARE(badDir.canonicalFilePath(), QString());
|
||||
|
||||
// This used to crash on Mac
|
||||
QFileInfo dontCrash(QLatin1String("/"));
|
||||
QCOMPARE(dontCrash.canonicalFilePath(), QLatin1String("/"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user