| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemengine_unix.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch> | - | ||||||||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||
| 42 | #include "qfilesystemengine_p.h" | - | ||||||||||||||||||||||||
| 43 | #include "qfile.h" | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | #include <QtCore/qvarlengtharray.h> | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | #include <stdlib.h> // for realpath() | - | ||||||||||||||||||||||||
| 48 | #include <sys/types.h> | - | ||||||||||||||||||||||||
| 49 | #include <sys/stat.h> | - | ||||||||||||||||||||||||
| 50 | #include <unistd.h> | - | ||||||||||||||||||||||||
| 51 | #include <stdio.h> | - | ||||||||||||||||||||||||
| 52 | #include <errno.h> | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||||||||
| 56 | # include <QtCore/private/qcore_mac_p.h> | - | ||||||||||||||||||||||||
| 57 | # include <CoreFoundation/CFBundle.h> | - | ||||||||||||||||||||||||
| 58 | #endif | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||
| 61 | #include <CoreServices/CoreServices.h> | - | ||||||||||||||||||||||||
| 62 | #endif | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | #ifdef Q_OS_IOS | - | ||||||||||||||||||||||||
| 65 | #include <MobileCoreServices/MobileCoreServices.h> | - | ||||||||||||||||||||||||
| 66 | #endif | - | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 69 | // We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but | - | ||||||||||||||||||||||||
| 70 | // we need these declarations: | - | ||||||||||||||||||||||||
| 71 | Q_FORWARD_DECLARE_OBJC_CLASS(NSString); | - | ||||||||||||||||||||||||
| 72 | extern "C" NSString *NSTemporaryDirectory(); | - | ||||||||||||||||||||||||
| 73 | #endif | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 78 | static inline bool hasResourcePropertyFlag(const QFileSystemMetaData &data, | - | ||||||||||||||||||||||||
| 79 | const QFileSystemEntry &entry, | - | ||||||||||||||||||||||||
| 80 | CFStringRef key) | - | ||||||||||||||||||||||||
| 81 | { | - | ||||||||||||||||||||||||
| 82 | QCFString path = CFStringCreateWithFileSystemRepresentation(0, | - | ||||||||||||||||||||||||
| 83 | entry.nativeFilePath().constData()); | - | ||||||||||||||||||||||||
| 84 | if (!path) | - | ||||||||||||||||||||||||
| 85 | return false; | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, | - | ||||||||||||||||||||||||
| 88 | data.hasFlags(QFileSystemMetaData::DirectoryType)); | - | ||||||||||||||||||||||||
| 89 | if (!url) | - | ||||||||||||||||||||||||
| 90 | return false; | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | CFBooleanRef value; | - | ||||||||||||||||||||||||
| 93 | if (CFURLCopyResourcePropertyForKey(url, key, &value, NULL)) { | - | ||||||||||||||||||||||||
| 94 | if (value == kCFBooleanTrue) | - | ||||||||||||||||||||||||
| 95 | return true; | - | ||||||||||||||||||||||||
| 96 | } | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | return false; | - | ||||||||||||||||||||||||
| 99 | } | - | ||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry) | - | ||||||||||||||||||||||||
| 102 | { | - | ||||||||||||||||||||||||
| 103 | if (!data.isDirectory()) | - | ||||||||||||||||||||||||
| 104 | return false; | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | QFileInfo info(entry.filePath()); | - | ||||||||||||||||||||||||
| 107 | QString suffix = info.suffix(); | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | if (suffix.length() > 0) { | - | ||||||||||||||||||||||||
| 110 | // First step: is the extension known ? | - | ||||||||||||||||||||||||
| 111 | QCFType<CFStringRef> extensionRef = QCFString::toCFStringRef(suffix); | - | ||||||||||||||||||||||||
| 112 | QCFType<CFStringRef> uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL); | - | ||||||||||||||||||||||||
| 113 | if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle)) | - | ||||||||||||||||||||||||
| 114 | return true; | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | // Second step: check if an application knows the package type | - | ||||||||||||||||||||||||
| 117 | QCFType<CFStringRef> path = QCFString::toCFStringRef(entry.filePath()); | - | ||||||||||||||||||||||||
| 118 | QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | UInt32 type, creator; | - | ||||||||||||||||||||||||
| 121 | // Well created packages have the PkgInfo file | - | ||||||||||||||||||||||||
| 122 | if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) | - | ||||||||||||||||||||||||
| 123 | return true; | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||
| 126 | // Find if an application other than Finder claims to know how to handle the package | - | ||||||||||||||||||||||||
| 127 | QCFType<CFURLRef> application; | - | ||||||||||||||||||||||||
| 128 | LSGetApplicationForURL(url, | - | ||||||||||||||||||||||||
| 129 | kLSRolesEditor|kLSRolesViewer|kLSRolesViewerkLSRolesEditor|kLSRolesViewer, | - | ||||||||||||||||||||||||
| 130 | NULL, | - | ||||||||||||||||||||||||
| 131 | &application); | - | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | if (application) { | - | ||||||||||||||||||||||||
| 134 | QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application); | - | ||||||||||||||||||||||||
| 135 | CFStringRef identifier = CFBundleGetIdentifier(bundle); | - | ||||||||||||||||||||||||
| 136 | QString applicationId = QCFString::toQString(identifier); | - | ||||||||||||||||||||||||
| 137 | if (applicationId != QLatin1String("com.apple.finder")) | - | ||||||||||||||||||||||||
| 138 | return true; | - | ||||||||||||||||||||||||
| 139 | } | - | ||||||||||||||||||||||||
| 140 | #endif | - | ||||||||||||||||||||||||
| 141 | } | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | // Third step: check if the directory has the package bit set | - | ||||||||||||||||||||||||
| 144 | return hasResourcePropertyFlag(data, entry, kCFURLIsPackageKey); | - | ||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||
| 146 | #endif | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | //static | - | ||||||||||||||||||||||||
| 149 | QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data) | - | ||||||||||||||||||||||||
| 150 | { | - | ||||||||||||||||||||||||
| 151 | #if defined(__GLIBC__) && !defined(PATH_MAX) | - | ||||||||||||||||||||||||
| 152 | #define PATH_CHUNK_SIZE 256 | - | ||||||||||||||||||||||||
| 153 | char *s = 0; | - | ||||||||||||||||||||||||
| 154 | int len = -1; | - | ||||||||||||||||||||||||
| 155 | int size = PATH_CHUNK_SIZE; | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | while (1) { | - | ||||||||||||||||||||||||
| 158 | s = (char *) ::realloc(s, size); | - | ||||||||||||||||||||||||
| 159 | Q_CHECK_PTR(s); | - | ||||||||||||||||||||||||
| 160 | len = ::readlink(link.nativeFilePath().constData(), s, size); | - | ||||||||||||||||||||||||
| 161 | if (len < 0) { | - | ||||||||||||||||||||||||
| 162 | ::free(s); | - | ||||||||||||||||||||||||
| 163 | break; | - | ||||||||||||||||||||||||
| 164 | } | - | ||||||||||||||||||||||||
| 165 | if (len < size) { | - | ||||||||||||||||||||||||
| 166 | break; | - | ||||||||||||||||||||||||
| 167 | } | - | ||||||||||||||||||||||||
| 168 | size *= 2; | - | ||||||||||||||||||||||||
| 169 | } | - | ||||||||||||||||||||||||
| 170 | #else | - | ||||||||||||||||||||||||
| 171 | char s[PATH_MAX+1]; | - | ||||||||||||||||||||||||
| 172 | int len = readlink(link.nativeFilePath().constData(), s, PATH_MAX); | - | ||||||||||||||||||||||||
| 173 | #endif | - | ||||||||||||||||||||||||
| 174 | if (len > 0) { | - | ||||||||||||||||||||||||
| 175 | QString ret; | - | ||||||||||||||||||||||||
| 176 | if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) | - | ||||||||||||||||||||||||
| 177 | fillMetaData(link, data, QFileSystemMetaData::DirectoryType); | - | ||||||||||||||||||||||||
| 178 | if (data.isDirectory() && s[0] != '/') { | - | ||||||||||||||||||||||||
| 179 | QDir parent(link.filePath()); | - | ||||||||||||||||||||||||
| 180 | parent.cdUp(); | - | ||||||||||||||||||||||||
| 181 | ret = parent.path(); | - | ||||||||||||||||||||||||
| 182 | if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 183 | ret += QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 184 | } | - | ||||||||||||||||||||||||
| 185 | s[len] = '\0'; | - | ||||||||||||||||||||||||
| 186 | ret += QFile::decodeName(QByteArray(s)); | - | ||||||||||||||||||||||||
| 187 | #if defined(__GLIBC__) && !defined(PATH_MAX) | - | ||||||||||||||||||||||||
| 188 | ::free(s); | - | ||||||||||||||||||||||||
| 189 | #endif | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | if (!ret.startsWith(QLatin1Char('/'))) { | - | ||||||||||||||||||||||||
| 192 | if (link.filePath().startsWith(QLatin1Char('/'))) { | - | ||||||||||||||||||||||||
| 193 | ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 194 | + QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 195 | } else { | - | ||||||||||||||||||||||||
| 196 | ret.prepend(QDir::currentPath() + QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 197 | } | - | ||||||||||||||||||||||||
| 198 | } | - | ||||||||||||||||||||||||
| 199 | ret = QDir::cleanPath(ret); | - | ||||||||||||||||||||||||
| 200 | if (ret.size() > 1 && ret.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 201 | ret.chop(1); | - | ||||||||||||||||||||||||
| 202 | return QFileSystemEntry(ret); | - | ||||||||||||||||||||||||
| 203 | } | - | ||||||||||||||||||||||||
| 204 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 205 | { | - | ||||||||||||||||||||||||
| 206 | QCFString path = CFStringCreateWithFileSystemRepresentation(0, | - | ||||||||||||||||||||||||
| 207 | QFile::encodeName(QDir::cleanPath(link.filePath())).data()); | - | ||||||||||||||||||||||||
| 208 | if (!path) | - | ||||||||||||||||||||||||
| 209 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, | - | ||||||||||||||||||||||||
| 212 | data.hasFlags(QFileSystemMetaData::DirectoryType)); | - | ||||||||||||||||||||||||
| 213 | if (!url) | - | ||||||||||||||||||||||||
| 214 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | QCFType<CFDataRef> bookmarkData = CFURLCreateBookmarkDataFromFile(0, url, NULL); | - | ||||||||||||||||||||||||
| 217 | if (!bookmarkData) | - | ||||||||||||||||||||||||
| 218 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | QCFType<CFURLRef> resolvedUrl = CFURLCreateByResolvingBookmarkData(0, | - | ||||||||||||||||||||||||
| 221 | bookmarkData, | - | ||||||||||||||||||||||||
| 222 | (CFURLBookmarkResolutionOptions)(kCFBookmarkResolutionWithoutUIMask | - | ||||||||||||||||||||||||
| 223 | | kCFBookmarkResolutionWithoutMountingMask), NULL, NULL, NULL, NULL); | - | ||||||||||||||||||||||||
| 224 | if (!resolvedUrl) | - | ||||||||||||||||||||||||
| 225 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | QCFString cfstr(CFURLCopyFileSystemPath(resolvedUrl, kCFURLPOSIXPathStyle)); | - | ||||||||||||||||||||||||
| 228 | if (!cfstr) | - | ||||||||||||||||||||||||
| 229 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | return QFileSystemEntry(QCFString::toQString(cfstr)); | - | ||||||||||||||||||||||||
| 232 | } | - | ||||||||||||||||||||||||
| 233 | #endif | - | ||||||||||||||||||||||||
| 234 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 235 | } | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | //static | - | ||||||||||||||||||||||||
| 238 | QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data) | - | ||||||||||||||||||||||||
| 239 | { | - | ||||||||||||||||||||||||
| 240 | if (entry.isEmpty() || entry.isRoot()) | - | ||||||||||||||||||||||||
| 241 | return entry; | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | #if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && !defined(Q_OS_ANDROID) && !defined(Q_OS_HAIKU) && _POSIX_VERSION < 200809L | - | ||||||||||||||||||||||||
| 244 | // realpath(X,0) is not supported | - | ||||||||||||||||||||||||
| 245 | Q_UNUSED(data); | - | ||||||||||||||||||||||||
| 246 | return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath())); | - | ||||||||||||||||||||||||
| 247 | #else | - | ||||||||||||||||||||||||
| 248 | char *ret = 0; | - | ||||||||||||||||||||||||
| 249 | # if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 250 | ret = (char*)malloc(PATH_MAX + 1); | - | ||||||||||||||||||||||||
| 251 | if (ret && realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { | - | ||||||||||||||||||||||||
| 252 | const int savedErrno = errno; // errno is checked below, and free() might change it | - | ||||||||||||||||||||||||
| 253 | free(ret); | - | ||||||||||||||||||||||||
| 254 | errno = savedErrno; | - | ||||||||||||||||||||||||
| 255 | ret = 0; | - | ||||||||||||||||||||||||
| 256 | } | - | ||||||||||||||||||||||||
| 257 | # elif defined(Q_OS_ANDROID) | - | ||||||||||||||||||||||||
| 258 | // On some Android versions, realpath() will return a path even if it does not exist | - | ||||||||||||||||||||||||
| 259 | // To work around this, we check existence in advance. | - | ||||||||||||||||||||||||
| 260 | if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute)) | - | ||||||||||||||||||||||||
| 261 | fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute); | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | if (!data.exists()) { | - | ||||||||||||||||||||||||
| 264 | ret = 0; | - | ||||||||||||||||||||||||
| 265 | errno = ENOENT; | - | ||||||||||||||||||||||||
| 266 | } else { | - | ||||||||||||||||||||||||
| 267 | ret = (char*)malloc(PATH_MAX + 1); | - | ||||||||||||||||||||||||
| 268 | if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { | - | ||||||||||||||||||||||||
| 269 | const int savedErrno = errno; // errno is checked below, and free() might change it | - | ||||||||||||||||||||||||
| 270 | free(ret); | - | ||||||||||||||||||||||||
| 271 | errno = savedErrno; | - | ||||||||||||||||||||||||
| 272 | ret = 0; | - | ||||||||||||||||||||||||
| 273 | } | - | ||||||||||||||||||||||||
| 274 | } | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | # else | - | ||||||||||||||||||||||||
| 277 | # if _POSIX_VERSION >= 200801L | - | ||||||||||||||||||||||||
| 278 | ret = realpath(entry.nativeFilePath().constData(), (char*)0); | - | ||||||||||||||||||||||||
| 279 | # else | - | ||||||||||||||||||||||||
| 280 | ret = (char*)malloc(PATH_MAX + 1); | - | ||||||||||||||||||||||||
| 281 | if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { | - | ||||||||||||||||||||||||
| 282 | const int savedErrno = errno; // errno is checked below, and free() might change it | - | ||||||||||||||||||||||||
| 283 | free(ret); | - | ||||||||||||||||||||||||
| 284 | errno = savedErrno; | - | ||||||||||||||||||||||||
| 285 | ret = 0; | - | ||||||||||||||||||||||||
| 286 | } | - | ||||||||||||||||||||||||
| 287 | # endif | - | ||||||||||||||||||||||||
| 288 | # endif | - | ||||||||||||||||||||||||
| 289 | if (ret) { | - | ||||||||||||||||||||||||
| 290 | data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute; | - | ||||||||||||||||||||||||
| 291 | data.entryFlags |= QFileSystemMetaData::ExistsAttribute; | - | ||||||||||||||||||||||||
| 292 | QString canonicalPath = QDir::cleanPath(QFile::decodeName(ret)); | - | ||||||||||||||||||||||||
| 293 | free(ret); | - | ||||||||||||||||||||||||
| 294 | return QFileSystemEntry(canonicalPath); | - | ||||||||||||||||||||||||
| 295 | } else if (errno == ENOENT) { // file doesn't exist | - | ||||||||||||||||||||||||
| 296 | data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute; | - | ||||||||||||||||||||||||
| 297 | data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute); | - | ||||||||||||||||||||||||
| 298 | return QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 299 | } | - | ||||||||||||||||||||||||
| 300 | return entry; | - | ||||||||||||||||||||||||
| 301 | #endif | - | ||||||||||||||||||||||||
| 302 | } | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | //static | - | ||||||||||||||||||||||||
| 305 | QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) | - | ||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||
| 307 | if (entry.isAbsolute() && entry.isClean()) | - | ||||||||||||||||||||||||
| 308 | return entry; | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | QByteArray orig = entry.nativeFilePath(); | - | ||||||||||||||||||||||||
| 311 | QByteArray result; | - | ||||||||||||||||||||||||
| 312 | if (orig.isEmpty() || !orig.startsWith('/')) { | - | ||||||||||||||||||||||||
| 313 | QFileSystemEntry cur(currentPath()); | - | ||||||||||||||||||||||||
| 314 | result = cur.nativeFilePath(); | - | ||||||||||||||||||||||||
| 315 | } | - | ||||||||||||||||||||||||
| 316 | if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) { | - | ||||||||||||||||||||||||
| 317 | if (!result.isEmpty() && !result.endsWith('/')) | - | ||||||||||||||||||||||||
| 318 | result.append('/'); | - | ||||||||||||||||||||||||
| 319 | result.append(orig); | - | ||||||||||||||||||||||||
| 320 | } | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | if (result.length() == 1 && result[0] == '/') | - | ||||||||||||||||||||||||
| 323 | return QFileSystemEntry(result, QFileSystemEntry::FromNativePath()); | - | ||||||||||||||||||||||||
| 324 | const bool isDir = result.endsWith('/'); | - | ||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||
| 326 | /* as long as QDir::cleanPath() operates on a QString we have to convert to a string here. | - | ||||||||||||||||||||||||
| 327 | * ideally we never convert to a string since that loses information. Please fix after | - | ||||||||||||||||||||||||
| 328 | * we get a QByteArray version of QDir::cleanPath() | - | ||||||||||||||||||||||||
| 329 | */ | - | ||||||||||||||||||||||||
| 330 | QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath()); | - | ||||||||||||||||||||||||
| 331 | QString stringVersion = QDir::cleanPath(resultingEntry.filePath()); | - | ||||||||||||||||||||||||
| 332 | if (isDir) | - | ||||||||||||||||||||||||
| 333 | stringVersion.append(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 334 | return QFileSystemEntry(stringVersion); | - | ||||||||||||||||||||||||
| 335 | } | - | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | //static | - | ||||||||||||||||||||||||
| 338 | QByteArray QFileSystemEngine::id(const QFileSystemEntry &entry) | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | struct stat statResult; | - | ||||||||||||||||||||||||
| 341 | if (stat(entry.nativeFilePath().constData(), &statResult)) { | - | ||||||||||||||||||||||||
| 342 | qErrnoWarning("stat() failed for '%s'", entry.nativeFilePath().constData()); | - | ||||||||||||||||||||||||
| 343 | return QByteArray(); | - | ||||||||||||||||||||||||
| 344 | } | - | ||||||||||||||||||||||||
| 345 | QByteArray result = QByteArray::number(quint64(statResult.st_dev), 16); | - | ||||||||||||||||||||||||
| 346 | result += ':'; | - | ||||||||||||||||||||||||
| 347 | result += QByteArray::number(quint64(statResult.st_ino)); | - | ||||||||||||||||||||||||
| 348 | return result; | - | ||||||||||||||||||||||||
| 349 | } | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | //static | - | ||||||||||||||||||||||||
| 352 | QString QFileSystemEngine::resolveUserName(uint userId) | - | ||||||||||||||||||||||||
| 353 | { | - | ||||||||||||||||||||||||
| 354 | #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) | - | ||||||||||||||||||||||||
| 355 | int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); | - | ||||||||||||||||||||||||
| 356 | if (size_max == -1)
| 0-1 | ||||||||||||||||||||||||
| 357 | size_max = 1024; never executed: size_max = 1024; | 0 | ||||||||||||||||||||||||
| 358 | QVarLengthArray<char, 1024> buf(size_max); | - | ||||||||||||||||||||||||
| 359 | #endif | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | #if !defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
| 362 | struct passwd *pw = 0; | - | ||||||||||||||||||||||||
| #if !defined(Q_OS_INTEGRITY)#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS) | ||||||||||||||||||||||||||
| 364 | struct passwd entry; | - | ||||||||||||||||||||||||
| 365 | getpwuid_r(userId, &entry, buf.data(), buf.size(), &pw); | - | ||||||||||||||||||||||||
| 366 | #else | - | ||||||||||||||||||||||||
| 367 | pw = getpwuid(userId); | - | ||||||||||||||||||||||||
| #endif#endif | ||||||||||||||||||||||||||
| 369 | if (pw)
| 0-1 | ||||||||||||||||||||||||
| 370 | return QFile::decodeName(QByteArray(pw->pw_name)); executed 1 time by 1 test: return QFile::decodeName(QByteArray(pw->pw_name));Executed by:
| 1 | ||||||||||||||||||||||||
| 371 | #endif | - | ||||||||||||||||||||||||
| 372 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 373 | } | - | ||||||||||||||||||||||||
| 374 | - | |||||||||||||||||||||||||
| 375 | //static | - | ||||||||||||||||||||||||
| 376 | QString QFileSystemEngine::resolveGroupName(uint groupId) | - | ||||||||||||||||||||||||
| 377 | { | - | ||||||||||||||||||||||||
| 378 | #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) | - | ||||||||||||||||||||||||
| 379 | int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); | - | ||||||||||||||||||||||||
| 380 | if (size_max == -1)
| 0-1 | ||||||||||||||||||||||||
| 381 | size_max = 1024; never executed: size_max = 1024; | 0 | ||||||||||||||||||||||||
| 382 | QVarLengthArray<char, 1024> buf(size_max); | - | ||||||||||||||||||||||||
| 383 | #endif | - | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | #if !defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
| 386 | struct group *gr = 0; | - | ||||||||||||||||||||||||
| #if !defined(Q_OS_INTEGRITY)#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS) | ||||||||||||||||||||||||||
| 388 | size_max = sysconf(_SC_GETGR_R_SIZE_MAX); | - | ||||||||||||||||||||||||
| 389 | if (size_max == -1)
| 0-1 | ||||||||||||||||||||||||
| 390 | size_max = 1024; never executed: size_max = 1024; | 0 | ||||||||||||||||||||||||
| 391 | buf.resize(size_max); | - | ||||||||||||||||||||||||
| 392 | struct group entry; | - | ||||||||||||||||||||||||
| 393 | // Some large systems have more members than the POSIX max size | - | ||||||||||||||||||||||||
| 394 | // Loop over by doubling the buffer size (upper limit 250k) | - | ||||||||||||||||||||||||
| 395 | for (unsigned size = size_max; size < 256000; size += size)
| 0-1 | ||||||||||||||||||||||||
| 396 | { | - | ||||||||||||||||||||||||
| 397 | buf.resize(size); | - | ||||||||||||||||||||||||
| 398 | // ERANGE indicates that the buffer was too small | - | ||||||||||||||||||||||||
| 399 | if (!getgrgid_r(groupId, &entry, buf.data(), buf.size(), &gr)
| 0-1 | ||||||||||||||||||||||||
| 400 | || errno != ERANGE)
| 0 | ||||||||||||||||||||||||
| 401 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 402 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 403 | #else | - | ||||||||||||||||||||||||
| 404 | gr = getgrgid(groupId); | - | ||||||||||||||||||||||||
| #endif#endif | ||||||||||||||||||||||||||
| 406 | if (gr)
| 0-1 | ||||||||||||||||||||||||
| 407 | return QFile::decodeName(QByteArray(gr->gr_name)); executed 1 time by 1 test: return QFile::decodeName(QByteArray(gr->gr_name));Executed by:
| 1 | ||||||||||||||||||||||||
| 408 | #endif | - | ||||||||||||||||||||||||
| 409 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 410 | } | - | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 413 | //static | - | ||||||||||||||||||||||||
| 414 | QString QFileSystemEngine::bundleName(const QFileSystemEntry &entry) | - | ||||||||||||||||||||||||
| 415 | { | - | ||||||||||||||||||||||||
| 416 | QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(entry.filePath()), | - | ||||||||||||||||||||||||
| 417 | kCFURLPOSIXPathStyle, true); | - | ||||||||||||||||||||||||
| 418 | if (QCFType<CFDictionaryRef> dict = CFBundleCopyInfoDictionaryForURL(url)) { | - | ||||||||||||||||||||||||
| 419 | if (CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) { | - | ||||||||||||||||||||||||
| 420 | if (CFGetTypeID(name) == CFStringGetTypeID()) | - | ||||||||||||||||||||||||
| 421 | return QCFString::toQString((CFStringRef)name); | - | ||||||||||||||||||||||||
| 422 | } | - | ||||||||||||||||||||||||
| 423 | } | - | ||||||||||||||||||||||||
| 424 | return QString(); | - | ||||||||||||||||||||||||
| 425 | } | - | ||||||||||||||||||||||||
| 426 | #endif | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | //static | - | ||||||||||||||||||||||||
| 429 | bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, | - | ||||||||||||||||||||||||
| 430 | QFileSystemMetaData::MetaDataFlags what) | - | ||||||||||||||||||||||||
| 431 | { | - | ||||||||||||||||||||||||
| 432 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 433 | if (what & QFileSystemMetaData::BundleType) { | - | ||||||||||||||||||||||||
| 434 | if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) | - | ||||||||||||||||||||||||
| 435 | what |= QFileSystemMetaData::DirectoryType; | - | ||||||||||||||||||||||||
| 436 | } | - | ||||||||||||||||||||||||
| 437 | if (what & QFileSystemMetaData::HiddenAttribute) { | - | ||||||||||||||||||||||||
| 438 | // OS X >= 10.5: st_flags & UF_HIDDEN | - | ||||||||||||||||||||||||
| 439 | what |= QFileSystemMetaData::PosixStatFlags; | - | ||||||||||||||||||||||||
| 440 | } | - | ||||||||||||||||||||||||
| 441 | #endif // defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | if (what & QFileSystemMetaData::PosixStatFlags) | - | ||||||||||||||||||||||||
| 444 | what |= QFileSystemMetaData::PosixStatFlags; | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | if (what & QFileSystemMetaData::ExistsAttribute) { | - | ||||||||||||||||||||||||
| 447 | // FIXME: Would other queries being performed provide this bit? | - | ||||||||||||||||||||||||
| 448 | what |= QFileSystemMetaData::PosixStatFlags; | - | ||||||||||||||||||||||||
| 449 | } | - | ||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||
| 451 | data.entryFlags &= ~what; | - | ||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | const char * nativeFilePath; | - | ||||||||||||||||||||||||
| 454 | int nativeFilePathLength; | - | ||||||||||||||||||||||||
| 455 | { | - | ||||||||||||||||||||||||
| 456 | const QByteArray &path = entry.nativeFilePath(); | - | ||||||||||||||||||||||||
| 457 | nativeFilePath = path.constData(); | - | ||||||||||||||||||||||||
| 458 | nativeFilePathLength = path.size(); | - | ||||||||||||||||||||||||
| 459 | Q_UNUSED(nativeFilePathLength); | - | ||||||||||||||||||||||||
| 460 | } | - | ||||||||||||||||||||||||
| 461 | - | |||||||||||||||||||||||||
| 462 | bool entryExists = true; // innocent until proven otherwise | - | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | QT_STATBUF statBuffer; | - | ||||||||||||||||||||||||
| 465 | bool statBufferValid = false; | - | ||||||||||||||||||||||||
| 466 | if (what & QFileSystemMetaData::LinkType) { | - | ||||||||||||||||||||||||
| 467 | if (QT_LSTAT(nativeFilePath, &statBuffer) == 0) { | - | ||||||||||||||||||||||||
| 468 | if (S_ISLNK(statBuffer.st_mode)) { | - | ||||||||||||||||||||||||
| 469 | data.entryFlags |= QFileSystemMetaData::LinkType; | - | ||||||||||||||||||||||||
| 470 | } else { | - | ||||||||||||||||||||||||
| 471 | statBufferValid = true; | - | ||||||||||||||||||||||||
| 472 | data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags; | - | ||||||||||||||||||||||||
| 473 | } | - | ||||||||||||||||||||||||
| 474 | } else { | - | ||||||||||||||||||||||||
| 475 | entryExists = false; | - | ||||||||||||||||||||||||
| 476 | } | - | ||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | data.knownFlagsMask |= QFileSystemMetaData::LinkType; | - | ||||||||||||||||||||||||
| 479 | } | - | ||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) { | - | ||||||||||||||||||||||||
| 482 | if (entryExists && !statBufferValid) | - | ||||||||||||||||||||||||
| 483 | statBufferValid = (QT_STAT(nativeFilePath, &statBuffer) == 0); | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | if (statBufferValid) | - | ||||||||||||||||||||||||
| 486 | data.fillFromStatBuf(statBuffer); | - | ||||||||||||||||||||||||
| 487 | else { | - | ||||||||||||||||||||||||
| 488 | entryExists = false; | - | ||||||||||||||||||||||||
| 489 | data.creationTime_ = 0; | - | ||||||||||||||||||||||||
| 490 | data.modificationTime_ = 0; | - | ||||||||||||||||||||||||
| 491 | data.accessTime_ = 0; | - | ||||||||||||||||||||||||
| 492 | data.size_ = 0; | - | ||||||||||||||||||||||||
| 493 | data.userId_ = (uint) -2; | - | ||||||||||||||||||||||||
| 494 | data.groupId_ = (uint) -2; | - | ||||||||||||||||||||||||
| 495 | } | - | ||||||||||||||||||||||||
| 496 | - | |||||||||||||||||||||||||
| 497 | // reset the mask | - | ||||||||||||||||||||||||
| 498 | data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags | - | ||||||||||||||||||||||||
| 499 | | QFileSystemMetaData::ExistsAttribute; | - | ||||||||||||||||||||||||
| 500 | } | - | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 503 | if (what & QFileSystemMetaData::AliasType) | - | ||||||||||||||||||||||||
| 504 | { | - | ||||||||||||||||||||||||
| 505 | if (entryExists && hasResourcePropertyFlag(data, entry, kCFURLIsAliasFileKey)) | - | ||||||||||||||||||||||||
| 506 | data.entryFlags |= QFileSystemMetaData::AliasType; | - | ||||||||||||||||||||||||
| 507 | data.knownFlagsMask |= QFileSystemMetaData::AliasType; | - | ||||||||||||||||||||||||
| 508 | } | - | ||||||||||||||||||||||||
| 509 | #endif | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | if (what & QFileSystemMetaData::UserPermissions) { | - | ||||||||||||||||||||||||
| 512 | // calculate user permissions | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | if (entryExists) { | - | ||||||||||||||||||||||||
| 515 | if (what & QFileSystemMetaData::UserReadPermission) { | - | ||||||||||||||||||||||||
| 516 | if (QT_ACCESS(nativeFilePath, R_OK) == 0) | - | ||||||||||||||||||||||||
| 517 | data.entryFlags |= QFileSystemMetaData::UserReadPermission; | - | ||||||||||||||||||||||||
| 518 | } | - | ||||||||||||||||||||||||
| 519 | if (what & QFileSystemMetaData::UserWritePermission) { | - | ||||||||||||||||||||||||
| 520 | if (QT_ACCESS(nativeFilePath, W_OK) == 0) | - | ||||||||||||||||||||||||
| 521 | data.entryFlags |= QFileSystemMetaData::UserWritePermission; | - | ||||||||||||||||||||||||
| 522 | } | - | ||||||||||||||||||||||||
| 523 | if (what & QFileSystemMetaData::UserExecutePermission) { | - | ||||||||||||||||||||||||
| 524 | if (QT_ACCESS(nativeFilePath, X_OK) == 0) | - | ||||||||||||||||||||||||
| 525 | data.entryFlags |= QFileSystemMetaData::UserExecutePermission; | - | ||||||||||||||||||||||||
| 526 | } | - | ||||||||||||||||||||||||
| 527 | } | - | ||||||||||||||||||||||||
| 528 | data.knownFlagsMask |= (what & QFileSystemMetaData::UserPermissions); | - | ||||||||||||||||||||||||
| 529 | } | - | ||||||||||||||||||||||||
| 530 | - | |||||||||||||||||||||||||
| 531 | if (what & QFileSystemMetaData::HiddenAttribute | - | ||||||||||||||||||||||||
| 532 | && !data.isHidden()) { | - | ||||||||||||||||||||||||
| 533 | QString fileName = entry.fileName(); | - | ||||||||||||||||||||||||
| 534 | if ((fileName.size() > 0 && fileName.at(0) == QLatin1Char('.')) | - | ||||||||||||||||||||||||
| 535 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 536 | || (entryExists && hasResourcePropertyFlag(data, entry, kCFURLIsHiddenKey)) | - | ||||||||||||||||||||||||
| 537 | #endif | - | ||||||||||||||||||||||||
| 538 | ) | - | ||||||||||||||||||||||||
| 539 | data.entryFlags |= QFileSystemMetaData::HiddenAttribute; | - | ||||||||||||||||||||||||
| 540 | data.knownFlagsMask |= QFileSystemMetaData::HiddenAttribute; | - | ||||||||||||||||||||||||
| 541 | } | - | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | #if defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
| 544 | if (what & QFileSystemMetaData::BundleType) { | - | ||||||||||||||||||||||||
| 545 | if (entryExists && isPackage(data, entry)) | - | ||||||||||||||||||||||||
| 546 | data.entryFlags |= QFileSystemMetaData::BundleType; | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | data.knownFlagsMask |= QFileSystemMetaData::BundleType; | - | ||||||||||||||||||||||||
| 549 | } | - | ||||||||||||||||||||||||
| 550 | #endif | - | ||||||||||||||||||||||||
| 551 | if (!entryExists) { | - | ||||||||||||||||||||||||
| 552 | data.clearFlags(what); | - | ||||||||||||||||||||||||
| 553 | return false; | - | ||||||||||||||||||||||||
| 554 | } | - | ||||||||||||||||||||||||
| 555 | return data.hasFlags(what); | - | ||||||||||||||||||||||||
| 556 | } | - | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| static//static | ||||||||||||||||||||||||||
| 559 | bool pathIsDirQFileSystemEngine::createDirectory(const QByteArray &nativeNameQFileSystemEntry &entry, bool createParents) | - | ||||||||||||||||||||||||
| 560 | { | - | ||||||||||||||||||||||||
| 561 | QT_STATBUF st; | - | ||||||||||||||||||||||||
| return QT_STAT(nativeName.constData(), &st) == 0 && (stQString dirName = entry.st_mode & S_IFMT) == S_IFDIR; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| static bool createDirectoryWithParentsfilePath(); | ||||||||||||||||||||||||||
| 562 | if
| 398-1425 | ||||||||||||||||||||||||
| 563 | ifdirName = QDir::cleanPath(shouldMkdirFirst && QT_MKDIRdirName); | - | ||||||||||||||||||||||||
| 564 | for
| 0-3059 | ||||||||||||||||||||||||
return true
| ||||||||||||||||||||||||||
| 565 | slash = dirName.indexOf(nativeNameQDir::separator(), oldslash+1); | - | ||||||||||||||||||||||||
| 566 | if (errno != ENOENTslash == -1) return false{
| 794-2265 | ||||||||||||||||||||||||
| 567 | if (oldslash == dirName.length())
| 396-398 | ||||||||||||||||||||||||
| 568 | break executed 396 times by 13 tests: ;break;Executed by:
executed 396 times by 13 tests: break;Executed by:
| 396 | ||||||||||||||||||||||||
| 569 | intslash = nativeNamedirName.lastIndexOf('/');length(); | - | ||||||||||||||||||||||||
| 570 | } executed 398 times by 13 tests: end of blockExecuted by:
| 398 | ||||||||||||||||||||||||
| 571 | if (slash< 1) return false;{
| 397-2266 | ||||||||||||||||||||||||
| 572 | const QByteArray parentNativeNamechunk = nativeNameQFile::encodeName(dirName.left(slash); | - | ||||||||||||||||||||||||
| if (!createDirectoryWithParents(parentNativeName)) | ||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||
| 573 | if (QT_MKDIR(nativeName,chunk.constData(), 0777) ==!= 0) return true;
| 497-1769 | ||||||||||||||||||||||||
return
| ||||||||||||||||||||||||||
| 574 | if (
| 0-1769 | ||||||||||||||||||||||||
| && pathIsDir(nativeName); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| bool QFileSystemEngine::createDirectory#if defined(const QFileSystemEntry &entry, bool createParentsQ_OS_QNX) | ||||||||||||||||||||||||||
| 576 | // On QNX the QNet (VFS paths of other hosts mounted under a directory | - | ||||||||||||||||||||||||
| 577 | // such as /net) mountpoint returns ENOENT, despite existing. stat() | - | ||||||||||||||||||||||||
| 578 | // on the QNet mountpoint returns successfully and reports S_IFDIR. | - | ||||||||||||||||||||||||
| 579 | || errno == ENOENT | - | ||||||||||||||||||||||||
| 580 | #endif | - | ||||||||||||||||||||||||
| 581 | ) { | - | ||||||||||||||||||||||||
| 582 | QString dirName = entry.filePath(); | - | ||||||||||||||||||||||||
| whileQT_STATBUF st; | ||||||||||||||||||||||||||
| 583 | if
| 0-1769 | ||||||||||||||||||||||||
| 584 | continue; executed 1767 times by 13 tests: continue;Executed by:
| 1767 | ||||||||||||||||||||||||
| 585 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 586 | return false; executed 2 times by 2 tests: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 587 | } | - | ||||||||||||||||||||||||
| 588 | } executed 497 times by 13 tests: end of blockExecuted by:
| 497 | ||||||||||||||||||||||||
| 589 | } executed 894 times by 13 tests: end of blockExecuted by:
| 894 | ||||||||||||||||||||||||
| 590 | return true; executed 396 times by 13 tests: return true;Executed by:
| 396 | ||||||||||||||||||||||||
| 591 | } | - | ||||||||||||||||||||||||
| 592 | #if defined(Q_OS_DARWIN) // Mac X doesn't support trailing /'s | - | ||||||||||||||||||||||||
| 593 | if (dirName.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 594 | dirName.chop(1); | - | ||||||||||||||||||||||||
| QByteArray nativeName =#endif | ||||||||||||||||||||||||||
| 596 | return (QT_MKDIR( executed 1425 times by 18 tests: QFile::encodeName(dirName);return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| 1425 | ||||||||||||||||||||||||
| if (QT_MKDIR(nativeName, executed 1425 times by 18 tests: ).constData(), 0777) == 0)return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| return true; executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| if (!createParents) executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| return false; executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| int savedErrno = errno; executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| bool pathChanged; executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| { executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| QString cleanName = QDir::cleanPath(dirName); executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| pathChanged = !dirName.isSharedWith(cleanName); executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| if (pathChanged) executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| nativeName = QFile::encodeName(cleanName); executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| } executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| errno = savedErrno; executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| return createDirectoryWithParents(nativeName, pathChanged executed 1425 times by 18 tests: );return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
executed 1425 times by 18 tests: return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0);Executed by:
| ||||||||||||||||||||||||||
| 597 | } | - | ||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||
| 599 | //static | - | ||||||||||||||||||||||||
| 600 | bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents) | - | ||||||||||||||||||||||||
| 601 | { | - | ||||||||||||||||||||||||
| 602 | if (removeEmptyParents) { | - | ||||||||||||||||||||||||
| 603 | QString dirName = QDir::cleanPath(entry.filePath()); | - | ||||||||||||||||||||||||
| 604 | for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) { | - | ||||||||||||||||||||||||
| 605 | const QByteArray chunk = QFile::encodeName(dirName.left(slash)); | - | ||||||||||||||||||||||||
| 606 | QT_STATBUF st; | - | ||||||||||||||||||||||||
| 607 | if (QT_STAT(chunk.constData(), &st) != -1) { | - | ||||||||||||||||||||||||
| 608 | if ((st.st_mode & S_IFMT) != S_IFDIR) | - | ||||||||||||||||||||||||
| 609 | return false; | - | ||||||||||||||||||||||||
| 610 | if (::rmdir(chunk.constData()) != 0) | - | ||||||||||||||||||||||||
| 611 | return oldslash != 0; | - | ||||||||||||||||||||||||
| 612 | } else { | - | ||||||||||||||||||||||||
| 613 | return false; | - | ||||||||||||||||||||||||
| 614 | } | - | ||||||||||||||||||||||||
| 615 | slash = dirName.lastIndexOf(QDir::separator(), oldslash-1); | - | ||||||||||||||||||||||||
| 616 | } | - | ||||||||||||||||||||||||
| 617 | return true; | - | ||||||||||||||||||||||||
| 618 | } | - | ||||||||||||||||||||||||
| 619 | return rmdir(QFile::encodeName(entry.filePath()).constData()) == 0; | - | ||||||||||||||||||||||||
| 620 | } | - | ||||||||||||||||||||||||
| 621 | - | |||||||||||||||||||||||||
| 622 | //static | - | ||||||||||||||||||||||||
| 623 | bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - | ||||||||||||||||||||||||
| 624 | { | - | ||||||||||||||||||||||||
| 625 | if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) | - | ||||||||||||||||||||||||
| 626 | return true; | - | ||||||||||||||||||||||||
| 627 | error = QSystemError(errno, QSystemError::StandardLibraryError); | - | ||||||||||||||||||||||||
| 628 | return false; | - | ||||||||||||||||||||||||
| 629 | } | - | ||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||
| 631 | //static | - | ||||||||||||||||||||||||
| 632 | bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - | ||||||||||||||||||||||||
| 633 | { | - | ||||||||||||||||||||||||
| 634 | Q_UNUSED(source); | - | ||||||||||||||||||||||||
| 635 | Q_UNUSED(target); | - | ||||||||||||||||||||||||
| 636 | error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented | - | ||||||||||||||||||||||||
| 637 | return false; | - | ||||||||||||||||||||||||
| 638 | } | - | ||||||||||||||||||||||||
| 639 | - | |||||||||||||||||||||||||
| 640 | //static | - | ||||||||||||||||||||||||
| 641 | bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - | ||||||||||||||||||||||||
| 642 | { | - | ||||||||||||||||||||||||
| 643 | if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) | - | ||||||||||||||||||||||||
| 644 | return true; | - | ||||||||||||||||||||||||
| 645 | error = QSystemError(errno, QSystemError::StandardLibraryError); | - | ||||||||||||||||||||||||
| 646 | return false; | - | ||||||||||||||||||||||||
| 647 | } | - | ||||||||||||||||||||||||
| 648 | - | |||||||||||||||||||||||||
| 649 | //static | - | ||||||||||||||||||||||||
| 650 | bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) | - | ||||||||||||||||||||||||
| 651 | { | - | ||||||||||||||||||||||||
| 652 | if (unlink(entry.nativeFilePath().constData()) == 0) | - | ||||||||||||||||||||||||
| 653 | return true; | - | ||||||||||||||||||||||||
| 654 | error = QSystemError(errno, QSystemError::StandardLibraryError); | - | ||||||||||||||||||||||||
| 655 | return false; | - | ||||||||||||||||||||||||
| 656 | - | |||||||||||||||||||||||||
| 657 | } | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | //static | - | ||||||||||||||||||||||||
| 660 | bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) | - | ||||||||||||||||||||||||
| 661 | { | - | ||||||||||||||||||||||||
| 662 | mode_t mode = 0; | - | ||||||||||||||||||||||||
| 663 | if (permissions & (QFile::ReadOwner | QFile::ReadUser)) | - | ||||||||||||||||||||||||
| 664 | mode |= S_IRUSR; | - | ||||||||||||||||||||||||
| 665 | if (permissions & (QFile::WriteOwner | QFile::WriteUser)) | - | ||||||||||||||||||||||||
| 666 | mode |= S_IWUSR; | - | ||||||||||||||||||||||||
| 667 | if (permissions & (QFile::ExeOwner | QFile::ExeUser)) | - | ||||||||||||||||||||||||
| 668 | mode |= S_IXUSR; | - | ||||||||||||||||||||||||
| 669 | if (permissions & QFile::ReadGroup) | - | ||||||||||||||||||||||||
| 670 | mode |= S_IRGRP; | - | ||||||||||||||||||||||||
| 671 | if (permissions & QFile::WriteGroup) | - | ||||||||||||||||||||||||
| 672 | mode |= S_IWGRP; | - | ||||||||||||||||||||||||
| 673 | if (permissions & QFile::ExeGroup) | - | ||||||||||||||||||||||||
| 674 | mode |= S_IXGRP; | - | ||||||||||||||||||||||||
| 675 | if (permissions & QFile::ReadOther) | - | ||||||||||||||||||||||||
| 676 | mode |= S_IROTH; | - | ||||||||||||||||||||||||
| 677 | if (permissions & QFile::WriteOther) | - | ||||||||||||||||||||||||
| 678 | mode |= S_IWOTH; | - | ||||||||||||||||||||||||
| 679 | if (permissions & QFile::ExeOther) | - | ||||||||||||||||||||||||
| 680 | mode |= S_IXOTH; | - | ||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | bool success = ::chmod(entry.nativeFilePath().constData(), mode) == 0; | - | ||||||||||||||||||||||||
| 683 | if (success && data) { | - | ||||||||||||||||||||||||
| 684 | data->entryFlags &= ~QFileSystemMetaData::Permissions; | - | ||||||||||||||||||||||||
| 685 | data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions)); | - | ||||||||||||||||||||||||
| 686 | data->knownFlagsMask |= QFileSystemMetaData::Permissions; | - | ||||||||||||||||||||||||
| 687 | } | - | ||||||||||||||||||||||||
| 688 | if (!success) | - | ||||||||||||||||||||||||
| 689 | error = QSystemError(errno, QSystemError::StandardLibraryError); | - | ||||||||||||||||||||||||
| 690 | return success; | - | ||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | QString QFileSystemEngine::homePath() | - | ||||||||||||||||||||||||
| 694 | { | - | ||||||||||||||||||||||||
| 695 | QString home = QFile::decodeName(qgetenv("HOME")); | - | ||||||||||||||||||||||||
| 696 | if (home.isEmpty()) | - | ||||||||||||||||||||||||
| 697 | home = rootPath(); | - | ||||||||||||||||||||||||
| 698 | return QDir::cleanPath(home); | - | ||||||||||||||||||||||||
| 699 | } | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | QString QFileSystemEngine::rootPath() | - | ||||||||||||||||||||||||
| 702 | { | - | ||||||||||||||||||||||||
| 703 | return QLatin1String("/"); | - | ||||||||||||||||||||||||
| 704 | } | - | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | QString QFileSystemEngine::tempPath() | - | ||||||||||||||||||||||||
| 707 | { | - | ||||||||||||||||||||||||
| 708 | #ifdef QT_UNIX_TEMP_PATH_OVERRIDE | - | ||||||||||||||||||||||||
| 709 | return QLatin1String(QT_UNIX_TEMP_PATH_OVERRIDE); | - | ||||||||||||||||||||||||
| #elif defined(Q_OS_BLACKBERRY) | ||||||||||||||||||||||||||
| QString temp = QFile::decodeName(qgetenv("TEMP")); | ||||||||||||||||||||||||||
| if (temp.isEmpty()) | ||||||||||||||||||||||||||
| temp = QFile::decodeName(qgetenv("TMPDIR")); | ||||||||||||||||||||||||||
| if (temp.isEmpty()) { | ||||||||||||||||||||||||||
| qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /var/tmp."); | ||||||||||||||||||||||||||
| temp = QLatin1String("/var/tmp"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return QDir::cleanPath(temp); | ||||||||||||||||||||||||||
| 710 | #else | - | ||||||||||||||||||||||||
| 711 | QString temp = QFile::decodeName(qgetenv("TMPDIR")); | - | ||||||||||||||||||||||||
| 712 | if (temp.isEmpty()) {
| 0-8783 | ||||||||||||||||||||||||
| 713 | #if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
| 714 | if (NSString *nsPath = NSTemporaryDirectory()) { | - | ||||||||||||||||||||||||
| 715 | temp = QString::fromCFString((CFStringRef)nsPath); | - | ||||||||||||||||||||||||
| 716 | } else { | - | ||||||||||||||||||||||||
| 717 | #else | - | ||||||||||||||||||||||||
| 718 | { | - | ||||||||||||||||||||||||
| 719 | #endif | - | ||||||||||||||||||||||||
| 720 | temp = QLatin1String("/tmp"); | - | ||||||||||||||||||||||||
| 721 | } | - | ||||||||||||||||||||||||
| 722 | } executed 8783 times by 49 tests: end of blockExecuted by:
| 8783 | ||||||||||||||||||||||||
| 723 | return QDir::cleanPath(temp); executed 8783 times by 49 tests: return QDir::cleanPath(temp);Executed by:
| 8783 | ||||||||||||||||||||||||
| 724 | #endif | - | ||||||||||||||||||||||||
| 725 | } | - | ||||||||||||||||||||||||
| 726 | - | |||||||||||||||||||||||||
| 727 | bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path) | - | ||||||||||||||||||||||||
| 728 | { | - | ||||||||||||||||||||||||
| 729 | int r; | - | ||||||||||||||||||||||||
| 730 | r = QT_CHDIR(path.nativeFilePath().constData()); | - | ||||||||||||||||||||||||
| 731 | return r >= 0; | - | ||||||||||||||||||||||||
| 732 | } | - | ||||||||||||||||||||||||
| 733 | - | |||||||||||||||||||||||||
| 734 | QFileSystemEntry QFileSystemEngine::currentPath() | - | ||||||||||||||||||||||||
| 735 | { | - | ||||||||||||||||||||||||
| 736 | QFileSystemEntry result; | - | ||||||||||||||||||||||||
| 737 | #if defined(__GLIBC__) && !defined(PATH_MAX) | - | ||||||||||||||||||||||||
| 738 | char *currentName = ::get_current_dir_name(); | - | ||||||||||||||||||||||||
| 739 | if (currentName) { | - | ||||||||||||||||||||||||
| 740 | result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); | - | ||||||||||||||||||||||||
| 741 | ::free(currentName); | - | ||||||||||||||||||||||||
| 742 | } | - | ||||||||||||||||||||||||
| 743 | #else | - | ||||||||||||||||||||||||
| 744 | char currentName[PATH_MAX+1]; | - | ||||||||||||||||||||||||
| 745 | if (::getcwd(currentName, PATH_MAX)) { | - | ||||||||||||||||||||||||
| 746 | #if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM) | - | ||||||||||||||||||||||||
| 747 | QByteArray dir(currentName); | - | ||||||||||||||||||||||||
| 748 | if (dir.indexOf(':') < dir.indexOf('/')) | - | ||||||||||||||||||||||||
| 749 | dir.remove(0, dir.indexOf(':')+1); | - | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | qstrncpy(currentName, dir.constData(), PATH_MAX); | - | ||||||||||||||||||||||||
| 752 | #endif | - | ||||||||||||||||||||||||
| 753 | result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); | - | ||||||||||||||||||||||||
| 754 | } | - | ||||||||||||||||||||||||
| 755 | # if defined(QT_DEBUG) | - | ||||||||||||||||||||||||
| 756 | if (result.isEmpty()) | - | ||||||||||||||||||||||||
| 757 | qWarning("QFileSystemEngine::currentPath: getcwd() failed"); | - | ||||||||||||||||||||||||
| 758 | # endif | - | ||||||||||||||||||||||||
| 759 | #endif | - | ||||||||||||||||||||||||
| 760 | return result; | - | ||||||||||||||||||||||||
| 761 | } | - | ||||||||||||||||||||||||
| 762 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |