Android: Fix canonical form of nonexistent paths
On some Android devices, the realpath() implementation will return the full path even if the path does not exist. This breaks the expectation of the canonical path, which should be empty for nonexistent paths. A few autotests failed due to this. To work around it, we query existence before getting the canonical path. [ChangeLog][Android] Fixed canonical path for nonexistent paths on some devices. Change-Id: I5c1dabb8b8394694bc74d2a91912800aaff6b9e3 Task-number: QTBUG-43705 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
4c6ab8f9e2
commit
2a86bf8ce0
@ -250,6 +250,26 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
|
||||
return QFileSystemEntry(ret);
|
||||
}
|
||||
}
|
||||
|
||||
# elif defined(Q_OS_ANDROID)
|
||||
// On some Android versions, realpath() will return a path even if it does not exist
|
||||
// To work around this, we check existence in advance.
|
||||
if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute))
|
||||
fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
|
||||
|
||||
if (!data.exists()) {
|
||||
ret = 0;
|
||||
errno = ENOENT;
|
||||
} else {
|
||||
ret = (char*)malloc(PATH_MAX + 1);
|
||||
if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
|
||||
const int savedErrno = errno; // errno is checked below, and free() might change it
|
||||
free(ret);
|
||||
errno = savedErrno;
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# else
|
||||
# if _POSIX_VERSION >= 200801L
|
||||
ret = realpath(entry.nativeFilePath().constData(), (char*)0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user