diff options
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index bfa4483ca7..10326dea06 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); @@ -723,36 +743,29 @@ bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path) QFileSystemEntry QFileSystemEngine::currentPath() { QFileSystemEntry result; - QT_STATBUF st; - if (QT_STAT(".", &st) == 0) { #if defined(__GLIBC__) && !defined(PATH_MAX) - char *currentName = ::get_current_dir_name(); - if (currentName) { - result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); - ::free(currentName); - } + char *currentName = ::get_current_dir_name(); + if (currentName) { + result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); + ::free(currentName); + } #else - char currentName[PATH_MAX+1]; - if (::getcwd(currentName, PATH_MAX)) { + char currentName[PATH_MAX+1]; + if (::getcwd(currentName, PATH_MAX)) { #if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM) - QByteArray dir(currentName); - if (dir.indexOf(':') < dir.indexOf('/')) - dir.remove(0, dir.indexOf(':')+1); + QByteArray dir(currentName); + if (dir.indexOf(':') < dir.indexOf('/')) + dir.remove(0, dir.indexOf(':')+1); - qstrncpy(currentName, dir.constData(), PATH_MAX); + qstrncpy(currentName, dir.constData(), PATH_MAX); #endif - result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); - } + result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); + } # if defined(QT_DEBUG) - if (result.isEmpty()) - qWarning("QFileSystemEngine::currentPath: getcwd() failed"); + if (result.isEmpty()) + qWarning("QFileSystemEngine::currentPath: getcwd() failed"); # endif #endif - } else { -# if defined(QT_DEBUG) - qWarning("QFileSystemEngine::currentPath: stat(\".\") failed"); -# endif - } return result; } QT_END_NAMESPACE |