| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | static inline bool _q_isMacHidden(const char *nativePath) | - |
| 17 | { | - |
| 18 | (void)nativePath;; | - |
| 19 | | - |
| 20 | return false; | - |
| 21 | } | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data) | - |
| 26 | { | - |
| 27 | char s[4096 +1]; | - |
| 28 | int len = readlink(link.nativeFilePath().constData(), s, 4096); | - |
| 29 | | - |
| 30 | if (len > 0) { | - |
| 31 | QString ret; | - |
| 32 | if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) | - |
| 33 | fillMetaData(link, data, QFileSystemMetaData::DirectoryType); | - |
| 34 | if (data.isDirectory() && s[0] != '/') { | - |
| 35 | QDir parent(link.filePath()); | - |
| 36 | parent.cdUp(); | - |
| 37 | ret = parent.path(); | - |
| 38 | if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) | - |
| 39 | ret += QLatin1Char('/'); | - |
| 40 | } | - |
| 41 | s[len] = '\0'; | - |
| 42 | ret += QFile::decodeName(QByteArray(s)); | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | if (!ret.startsWith(QLatin1Char('/'))) { | - |
| 48 | if (link.filePath().startsWith(QLatin1Char('/'))) { | - |
| 49 | ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/'))) | - |
| 50 | + QLatin1Char('/')); | - |
| 51 | } else { | - |
| 52 | ret.prepend(QDir::currentPath() + QLatin1Char('/')); | - |
| 53 | } | - |
| 54 | } | - |
| 55 | ret = QDir::cleanPath(ret); | - |
| 56 | if (ret.size() > 1 && ret.endsWith(QLatin1Char('/'))) | - |
| 57 | ret.chop(1); | - |
| 58 | return QFileSystemEntry(ret); | - |
| 59 | } | - |
| 60 | return QFileSystemEntry(); | - |
| 61 | } | - |
| 62 | | - |
| 63 | | - |
| 64 | QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data) | - |
| 65 | { | - |
| 66 | if (entry.isEmpty() || entry.isRoot()) partially evaluated: entry.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:2288 |
evaluated: entry.isRoot()| yes Evaluation Count:68 | yes Evaluation Count:2220 |
| 0-2288 |
| 67 | return entry; executed: return entry;Execution Count:68 | 68 |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | char *ret = 0; | - |
| 75 | ret = realpath(entry.nativeFilePath().constData(), (char*)0); | - |
| 76 | if (ret) { evaluated: ret| yes Evaluation Count:2207 | yes Evaluation Count:13 |
| 13-2207 |
| 77 | data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute; | - |
| 78 | data.entryFlags |= QFileSystemMetaData::ExistsAttribute; | - |
| 79 | QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret)); | - |
| 80 | free(ret); | - |
| 81 | return QFileSystemEntry(canonicalPath); executed: return QFileSystemEntry(canonicalPath);Execution Count:2207 | 2207 |
| 82 | } else if ((*__errno_location ()) == 2) { partially evaluated: (*__errno_location ()) == 2| yes Evaluation Count:13 | no Evaluation Count:0 |
| 0-13 |
| 83 | data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute; | - |
| 84 | data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute); | - |
| 85 | return QFileSystemEntry(); executed: return QFileSystemEntry();Execution Count:13 | 13 |
| 86 | } | - |
| 87 | return entry; never executed: return entry; | 0 |
| 88 | | - |
| 89 | } | - |
| 90 | | - |
| 91 | | - |
| 92 | QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) | - |
| 93 | { | - |
| 94 | if (entry.isAbsolute() && entry.isClean()) | - |
| 95 | return entry; | - |
| 96 | | - |
| 97 | QByteArray orig = entry.nativeFilePath(); | - |
| 98 | QByteArray result; | - |
| 99 | if (orig.isEmpty() || !orig.startsWith('/')) { | - |
| 100 | QFileSystemEntry cur(currentPath()); | - |
| 101 | result = cur.nativeFilePath(); | - |
| 102 | } | - |
| 103 | if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) { | - |
| 104 | if (!result.isEmpty() && !result.endsWith('/')) | - |
| 105 | result.append('/'); | - |
| 106 | result.append(orig); | - |
| 107 | } | - |
| 108 | | - |
| 109 | if (result.length() == 1 && result[0] == '/') | - |
| 110 | return QFileSystemEntry(result, QFileSystemEntry::FromNativePath()); | - |
| 111 | const bool isDir = result.endsWith('/'); | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath()); | - |
| 118 | QString stringVersion = QDir::cleanPath(resultingEntry.filePath()); | - |
| 119 | if (isDir) | - |
| 120 | stringVersion.append(QLatin1Char('/')); | - |
| 121 | return QFileSystemEntry(stringVersion); | - |
| 122 | } | - |
| 123 | | - |
| 124 | | - |
| 125 | QByteArray QFileSystemEngine::id(const QFileSystemEntry &entry) | - |
| 126 | { | - |
| 127 | struct stat statResult; | - |
| 128 | if (stat(entry.nativeFilePath().constData(), &statResult)) { never evaluated: stat(entry.nativeFilePath().constData(), &statResult) | 0 |
| 129 | qErrnoWarning("stat() failed for '%s'", entry.nativeFilePath().constData()); | - |
| 130 | return QByteArray(); never executed: return QByteArray(); | 0 |
| 131 | } | - |
| 132 | QByteArray result = QByteArray::number(quint64(statResult.st_dev), 16); | - |
| 133 | result += ':'; | - |
| 134 | result += QByteArray::number(quint64(statResult.st_ino)); | - |
| 135 | return result; never executed: return result; | 0 |
| 136 | } | - |
| 137 | | - |
| 138 | | - |
| 139 | QString QFileSystemEngine::resolveUserName(uint userId) | - |
| 140 | { | - |
| 141 | | - |
| 142 | int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); | - |
| 143 | if (size_max == -1) | - |
| 144 | size_max = 1024; | - |
| 145 | QVarLengthArray<char, 1024> buf(size_max); | - |
| 146 | | - |
| 147 | | - |
| 148 | struct passwd *pw = 0; | - |
| 149 | | - |
| 150 | | - |
| 151 | struct passwd entry; | - |
| 152 | getpwuid_r(userId, &entry, buf.data(), buf.size(), &pw); | - |
| 153 | | - |
| 154 | | - |
| 155 | | - |
| 156 | | - |
| 157 | if (pw) | - |
| 158 | return QFile::decodeName(QByteArray(pw->pw_name)); | - |
| 159 | return QString(); | - |
| 160 | } | - |
| 161 | | - |
| 162 | | - |
| 163 | QString QFileSystemEngine::resolveGroupName(uint groupId) | - |
| 164 | { | - |
| 165 | | - |
| 166 | int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); | - |
| 167 | if (size_max == -1) | - |
| 168 | size_max = 1024; | - |
| 169 | QVarLengthArray<char, 1024> buf(size_max); | - |
| 170 | | - |
| 171 | | - |
| 172 | struct group *gr = 0; | - |
| 173 | | - |
| 174 | | - |
| 175 | size_max = sysconf(_SC_GETGR_R_SIZE_MAX); | - |
| 176 | if (size_max == -1) | - |
| 177 | size_max = 1024; | - |
| 178 | buf.resize(size_max); | - |
| 179 | struct group entry; | - |
| 180 | | - |
| 181 | | - |
| 182 | for (unsigned size = size_max; size < 256000; size += size) | - |
| 183 | { | - |
| 184 | buf.resize(size); | - |
| 185 | | - |
| 186 | if (!getgrgid_r(groupId, &entry, buf.data(), buf.size(), &gr) | - |
| 187 | || (*__errno_location ()) != 34) | - |
| 188 | break; | - |
| 189 | } | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | | - |
| 194 | if (gr) | - |
| 195 | return QFile::decodeName(QByteArray(gr->gr_name)); | - |
| 196 | return QString(); | - |
| 197 | } | - |
| 198 | bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, | - |
| 199 | QFileSystemMetaData::MetaDataFlags what) | - |
| 200 | { | - |
| 201 | if (what & QFileSystemMetaData::PosixStatFlags) | - |
| 202 | what |= QFileSystemMetaData::PosixStatFlags; | - |
| 203 | | - |
| 204 | if (what & QFileSystemMetaData::ExistsAttribute) { | - |
| 205 | | - |
| 206 | what |= QFileSystemMetaData::PosixStatFlags; | - |
| 207 | } | - |
| 208 | | - |
| 209 | data.entryFlags &= ~what; | - |
| 210 | | - |
| 211 | const char * nativeFilePath; | - |
| 212 | int nativeFilePathLength; | - |
| 213 | { | - |
| 214 | const QByteArray &path = entry.nativeFilePath(); | - |
| 215 | nativeFilePath = path.constData(); | - |
| 216 | nativeFilePathLength = path.size(); | - |
| 217 | (void)nativeFilePathLength;; | - |
| 218 | } | - |
| 219 | | - |
| 220 | bool entryExists = true; | - |
| 221 | | - |
| 222 | struct stat64 statBuffer; | - |
| 223 | bool statBufferValid = false; | - |
| 224 | if (what & QFileSystemMetaData::LinkType) { | - |
| 225 | if (::lstat64(nativeFilePath, &statBuffer) == 0) { | - |
| 226 | if (((((statBuffer.st_mode)) & 0170000) == (0120000))) { | - |
| 227 | data.entryFlags |= QFileSystemMetaData::LinkType; | - |
| 228 | } else { | - |
| 229 | statBufferValid = true; | - |
| 230 | data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags; | - |
| 231 | } | - |
| 232 | } else { | - |
| 233 | entryExists = false; | - |
| 234 | } | - |
| 235 | | - |
| 236 | data.knownFlagsMask |= QFileSystemMetaData::LinkType; | - |
| 237 | } | - |
| 238 | | - |
| 239 | if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) { | - |
| 240 | if (entryExists && !statBufferValid) | - |
| 241 | statBufferValid = (::stat64(nativeFilePath, &statBuffer) == 0); | - |
| 242 | | - |
| 243 | if (statBufferValid) | - |
| 244 | data.fillFromStatBuf(statBuffer); | - |
| 245 | else { | - |
| 246 | entryExists = false; | - |
| 247 | data.creationTime_ = 0; | - |
| 248 | data.modificationTime_ = 0; | - |
| 249 | data.accessTime_ = 0; | - |
| 250 | data.size_ = 0; | - |
| 251 | data.userId_ = (uint) -2; | - |
| 252 | data.groupId_ = (uint) -2; | - |
| 253 | } | - |
| 254 | | - |
| 255 | | - |
| 256 | data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags | - |
| 257 | | QFileSystemMetaData::ExistsAttribute; | - |
| 258 | } | - |
| 259 | if (what & QFileSystemMetaData::UserPermissions) { | - |
| 260 | | - |
| 261 | | - |
| 262 | if (entryExists) { | - |
| 263 | if (what & QFileSystemMetaData::UserReadPermission) { | - |
| 264 | if (::access(nativeFilePath, 4) == 0) | - |
| 265 | data.entryFlags |= QFileSystemMetaData::UserReadPermission; | - |
| 266 | } | - |
| 267 | if (what & QFileSystemMetaData::UserWritePermission) { | - |
| 268 | if (::access(nativeFilePath, 2) == 0) | - |
| 269 | data.entryFlags |= QFileSystemMetaData::UserWritePermission; | - |
| 270 | } | - |
| 271 | if (what & QFileSystemMetaData::UserExecutePermission) { | - |
| 272 | if (::access(nativeFilePath, 1) == 0) | - |
| 273 | data.entryFlags |= QFileSystemMetaData::UserExecutePermission; | - |
| 274 | } | - |
| 275 | } | - |
| 276 | data.knownFlagsMask |= (what & QFileSystemMetaData::UserPermissions); | - |
| 277 | } | - |
| 278 | | - |
| 279 | if (what & QFileSystemMetaData::HiddenAttribute | - |
| 280 | && !data.isHidden()) { | - |
| 281 | QString fileName = entry.fileName(); | - |
| 282 | if ((fileName.size() > 0 && fileName.at(0) == QLatin1Char('.')) | - |
| 283 | || (entryExists && _q_isMacHidden(nativeFilePath))) | - |
| 284 | data.entryFlags |= QFileSystemMetaData::HiddenAttribute; | - |
| 285 | data.knownFlagsMask |= QFileSystemMetaData::HiddenAttribute; | - |
| 286 | } | - |
| 287 | if (!entryExists) { | - |
| 288 | data.clearFlags(what); | - |
| 289 | return false; | - |
| 290 | } | - |
| 291 | return data.hasFlags(what); | - |
| 292 | } | - |
| 293 | | - |
| 294 | | - |
| 295 | bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool createParents) | - |
| 296 | { | - |
| 297 | QString dirName = entry.filePath(); | - |
| 298 | if (createParents) { | - |
| 299 | dirName = QDir::cleanPath(dirName); | - |
| 300 | for (int oldslash = -1, slash=0; slash != -1; oldslash = slash) { | - |
| 301 | slash = dirName.indexOf(QDir::separator(), oldslash+1); | - |
| 302 | if (slash == -1) { | - |
| 303 | if (oldslash == dirName.length()) | - |
| 304 | break; | - |
| 305 | slash = dirName.length(); | - |
| 306 | } | - |
| 307 | if (slash) { | - |
| 308 | const QByteArray chunk = QFile::encodeName(dirName.left(slash)); | - |
| 309 | struct stat64 st; | - |
| 310 | if (::stat64(chunk.constData(), &st) != -1) { | - |
| 311 | if ((st.st_mode & 0170000) != 0040000) | - |
| 312 | return false; | - |
| 313 | } else if (::mkdir(chunk.constData(), 0777) != 0) { | - |
| 314 | return false; | - |
| 315 | } | - |
| 316 | } | - |
| 317 | } | - |
| 318 | return true; | - |
| 319 | } | - |
| 320 | | - |
| 321 | | - |
| 322 | | - |
| 323 | | - |
| 324 | return (::mkdir(QFile::encodeName(dirName).constData(), 0777) == 0); | - |
| 325 | } | - |
| 326 | | - |
| 327 | | - |
| 328 | bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents) | - |
| 329 | { | - |
| 330 | if (removeEmptyParents) { | - |
| 331 | QString dirName = QDir::cleanPath(entry.filePath()); | - |
| 332 | for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) { | - |
| 333 | const QByteArray chunk = QFile::encodeName(dirName.left(slash)); | - |
| 334 | struct stat64 st; | - |
| 335 | if (::stat64(chunk.constData(), &st) != -1) { | - |
| 336 | if ((st.st_mode & 0170000) != 0040000) | - |
| 337 | return false; | - |
| 338 | if (::rmdir(chunk.constData()) != 0) | - |
| 339 | return oldslash != 0; | - |
| 340 | } else { | - |
| 341 | return false; | - |
| 342 | } | - |
| 343 | slash = dirName.lastIndexOf(QDir::separator(), oldslash-1); | - |
| 344 | } | - |
| 345 | return true; | - |
| 346 | } | - |
| 347 | return rmdir(QFile::encodeName(entry.filePath()).constData()) == 0; | - |
| 348 | } | - |
| 349 | | - |
| 350 | | - |
| 351 | bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - |
| 352 | { | - |
| 353 | if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) | - |
| 354 | return true; | - |
| 355 | error = QSystemError((*__errno_location ()), QSystemError::StandardLibraryError); | - |
| 356 | return false; | - |
| 357 | } | - |
| 358 | | - |
| 359 | | - |
| 360 | bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - |
| 361 | { | - |
| 362 | (void)source;; | - |
| 363 | (void)target;; | - |
| 364 | error = QSystemError(38, QSystemError::StandardLibraryError); | - |
| 365 | return false; | - |
| 366 | } | - |
| 367 | | - |
| 368 | | - |
| 369 | bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) | - |
| 370 | { | - |
| 371 | if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) | - |
| 372 | return true; | - |
| 373 | error = QSystemError((*__errno_location ()), QSystemError::StandardLibraryError); | - |
| 374 | return false; | - |
| 375 | } | - |
| 376 | | - |
| 377 | | - |
| 378 | bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) | - |
| 379 | { | - |
| 380 | if (unlink(entry.nativeFilePath().constData()) == 0) | - |
| 381 | return true; | - |
| 382 | error = QSystemError((*__errno_location ()), QSystemError::StandardLibraryError); | - |
| 383 | return false; | - |
| 384 | | - |
| 385 | } | - |
| 386 | | - |
| 387 | | - |
| 388 | bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) | - |
| 389 | { | - |
| 390 | mode_t mode = 0; | - |
| 391 | if (permissions & QFile::ReadOwner) | - |
| 392 | mode |= 0400; | - |
| 393 | if (permissions & QFile::WriteOwner) | - |
| 394 | mode |= 0200; | - |
| 395 | if (permissions & QFile::ExeOwner) | - |
| 396 | mode |= 0100; | - |
| 397 | if (permissions & QFile::ReadUser) | - |
| 398 | mode |= 0400; | - |
| 399 | if (permissions & QFile::WriteUser) | - |
| 400 | mode |= 0200; | - |
| 401 | if (permissions & QFile::ExeUser) | - |
| 402 | mode |= 0100; | - |
| 403 | if (permissions & QFile::ReadGroup) | - |
| 404 | mode |= (0400 >> 3); | - |
| 405 | if (permissions & QFile::WriteGroup) | - |
| 406 | mode |= (0200 >> 3); | - |
| 407 | if (permissions & QFile::ExeGroup) | - |
| 408 | mode |= (0100 >> 3); | - |
| 409 | if (permissions & QFile::ReadOther) | - |
| 410 | mode |= ((0400 >> 3) >> 3); | - |
| 411 | if (permissions & QFile::WriteOther) | - |
| 412 | mode |= ((0200 >> 3) >> 3); | - |
| 413 | if (permissions & QFile::ExeOther) | - |
| 414 | mode |= ((0100 >> 3) >> 3); | - |
| 415 | | - |
| 416 | bool success = ::chmod(entry.nativeFilePath().constData(), mode) == 0; | - |
| 417 | if (success && data) { | - |
| 418 | data->entryFlags &= ~QFileSystemMetaData::Permissions; | - |
| 419 | data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions)); | - |
| 420 | data->knownFlagsMask |= QFileSystemMetaData::Permissions; | - |
| 421 | } | - |
| 422 | if (!success) | - |
| 423 | error = QSystemError((*__errno_location ()), QSystemError::StandardLibraryError); | - |
| 424 | return success; | - |
| 425 | } | - |
| 426 | | - |
| 427 | QString QFileSystemEngine::homePath() | - |
| 428 | { | - |
| 429 | QString home = QFile::decodeName(qgetenv("HOME")); | - |
| 430 | if (home.isNullisEmpty()) evaluated: home.isEmpty()| yes Evaluation Count:1 | yes Evaluation Count:793 |
| 1-793 |
| 431 | home = rootPath(); executed: home = rootPath();Execution Count:1 | 1 |
| 432 | return QDir::cleanPath(home); executed: return QDir::cleanPath(home);Execution Count:794 | 794 |
| 433 | } | - |
| 434 | | - |
| 435 | QString QFileSystemEngine::rootPath() | - |
| 436 | { | - |
| 437 | return QLatin1String("/"); | - |
| 438 | } | - |
| 439 | | - |
| 440 | QString QFileSystemEngine::tempPath() | - |
| 441 | { | - |
| 442 | QString temp = QFile::decodeName(qgetenv("TMPDIR")); | - |
| 443 | if (temp.isEmpty()) | - |
| 444 | temp = QLatin1String("/tmp/"); | - |
| 445 | return QDir::cleanPath(temp); | - |
| 446 | | - |
| 447 | } | - |
| 448 | | - |
| 449 | bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path) | - |
| 450 | { | - |
| 451 | int r; | - |
| 452 | r = ::chdir(path.nativeFilePath().constData()); | - |
| 453 | return r >= 0; | - |
| 454 | } | - |
| 455 | | - |
| 456 | QFileSystemEntry QFileSystemEngine::currentPath() | - |
| 457 | { | - |
| 458 | QFileSystemEntry result; | - |
| 459 | struct stat64 st; | - |
| 460 | if (::stat64(".", &st) == 0) { | - |
| 461 | | - |
| 462 | | - |
| 463 | | - |
| 464 | | - |
| 465 | | - |
| 466 | | - |
| 467 | | - |
| 468 | char currentName[4096 +1]; | - |
| 469 | if (::getcwd(currentName, 4096)) | - |
| 470 | result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); | - |
| 471 | | - |
| 472 | | - |
| 473 | | - |
| 474 | | - |
| 475 | | - |
| 476 | } else { | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | } | - |
| 481 | return result; | - |
| 482 | } | - |
| 483 | | - |
| 484 | | - |
| | |