diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2015-01-08 10:29:12 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2015-01-19 12:21:19 +0100 |
commit | 2a86bf8ce018cdca3c9e93fb36102ae440d1a114 (patch) | |
tree | b3225de9a0370554f7840f46f16dcbdfb994fdda /src/corelib/io | |
parent | 4c6ab8f9e265dc0e5ac7fb6282ba21f116f1f4a7 (diff) |
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>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 11d421591a..feb86d2895 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -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); |