io/qfilesystemengine_unix.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qplatformdefs.h" -
43#include "qfilesystemengine_p.h" -
44#include "qfile.h" -
45 -
46#include <QtCore/qvarlengtharray.h> -
47 -
48#include <stdlib.h> // for realpath() -
49#include <sys/types.h> -
50#include <sys/stat.h> -
51#include <unistd.h> -
52#include <stdio.h> -
53#include <errno.h> -
54 -
55 -
56#if defined(Q_OS_MAC) -
57# include <QtCore/private/qcore_mac_p.h> -
58#endif -
59 -
60QT_BEGIN_NAMESPACE -
61 -
62#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
63static inline bool _q_isMacHidden(const char *nativePath) -
64{ -
65 OSErr err; -
66 -
67 FSRef fsRef; -
68 err = FSPathMakeRefWithOptions(reinterpret_cast<const UInt8 *>(nativePath), -
69 kFSPathMakeRefDoNotFollowLeafSymlink, &fsRef, 0); -
70 if (err != noErr) -
71 return false; -
72 -
73 FSCatalogInfo catInfo; -
74 err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL); -
75 if (err != noErr) -
76 return false; -
77 -
78 FileInfo * const fileInfo = reinterpret_cast<FileInfo*>(&catInfo.finderInfo); -
79 return (fileInfo->finderFlags & kIsInvisible); -
80} -
81#else -
82static inline bool _q_isMacHidden(const char *nativePath) -
83{ -
84 Q_UNUSED(nativePath); -
85 // no-op -
86 return false; -
87} -
88#endif -
89 -
90//static -
91QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data) -
92{ -
93#if defined(__GLIBC__) && !defined(PATH_MAX) -
94#define PATH_CHUNK_SIZE 256 -
95 char *s = 0; -
96 int len = -1; -
97 int size = PATH_CHUNK_SIZE; -
98 -
99 while (1) { -
100 s = (char *) ::realloc(s, size); -
101 Q_CHECK_PTR(s); -
102 len = ::readlink(link.nativeFilePath().constData(), s, size); -
103 if (len < 0) { -
104 ::free(s); -
105 break; -
106 } -
107 if (len < size) { -
108 break; -
109 } -
110 size *= 2; -
111 } -
112#else -
113 char s[PATH_MAX+1]; -
114 int len = readlink(link.nativeFilePath().constData(), s, PATH_MAX); -
115#endif -
116 if (len > 0) { -
117 QString ret; -
118 if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) -
119 fillMetaData(link, data, QFileSystemMetaData::DirectoryType); -
120 if (data.isDirectory() && s[0] != '/') { -
121 QDir parent(link.filePath()); -
122 parent.cdUp(); -
123 ret = parent.path(); -
124 if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) -
125 ret += QLatin1Char('/'); -
126 } -
127 s[len] = '\0'; -
128 ret += QFile::decodeName(QByteArray(s)); -
129#if defined(__GLIBC__) && !defined(PATH_MAX) -
130 ::free(s); -
131#endif -
132 -
133 if (!ret.startsWith(QLatin1Char('/'))) { -
134 if (link.filePath().startsWith(QLatin1Char('/'))) { -
135 ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/'))) -
136 + QLatin1Char('/')); -
137 } else { -
138 ret.prepend(QDir::currentPath() + QLatin1Char('/')); -
139 } -
140 } -
141 ret = QDir::cleanPath(ret); -
142 if (ret.size() > 1 && ret.endsWith(QLatin1Char('/'))) -
143 ret.chop(1); -
144 return QFileSystemEntry(ret); -
145 } -
146#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
147 { -
148 FSRef fref; -
149 if (FSPathMakeRef((const UInt8 *)QFile::encodeName(QDir::cleanPath(link.filePath())).data(), &fref, 0) == noErr) { -
150 // TODO get the meta data info from the QFileSystemMetaData object -
151 Boolean isAlias, isFolder; -
152 if (FSResolveAliasFile(&fref, true, &isFolder, &isAlias) == noErr && isAlias) { -
153 AliasHandle alias; -
154 if (FSNewAlias(0, &fref, &alias) == noErr && alias) { -
155 QCFString cfstr; -
156 if (FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr) -
157 return QFileSystemEntry(QCFString::toQString(cfstr)); -
158 } -
159 } -
160 } -
161 } -
162#endif -
163 return QFileSystemEntry(); -
164} -
165 -
166//static -
167QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data) -
168{ -
169 if (entry.isEmpty() || entry.isRoot())
partially evaluated: entry.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2288
evaluated: entry.isRoot()
TRUEFALSE
yes
Evaluation Count:68
yes
Evaluation Count:2220
0-2288
170 return entry;
executed: return entry;
Execution Count:68
68
171 -
172#if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && _POSIX_VERSION < 200809L -
173 // realpath(X,0) is not supported -
174 Q_UNUSED(data); -
175 return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath())); -
176#else -
177 char *ret = 0;
executed (the execution status of this line is deduced): char *ret = 0;
-
178# if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
179 // Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here.-
/ When using -mmacosx-version-min=10.4, we get the legacy realpath implementation,
180 // which does not work properly with the realpath(X,0) form. See QTBUG-28282. -
181 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { -
182 ret = (char*)malloc(PATH_MAX + 1); -
183 if (ret && realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { -
184 const int savedErrno = errno; // errno is checked below, and free() might change it -
185 free(ret); -
186 errno = savedErrno; -
187 ret = 0; -
188 } -
189 } else { -
190 // on 10.5 we can use FSRef to resolve the file path. -
191 QString path = QDir::cleanPath(entry.filePath()); -
192 FSRef fsref; -
193 if (FSPathMakeRef((const UInt8 *)path.toUtf8().data(), &fsref, 0) == noErr) { -
194 CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref); -
195 CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle); -
196 QString ret = QCFString::toQString(canonicalPath); -
197 CFRelease(canonicalPath); -
198 CFRelease(urlref); -
199 return QFileSystemEntry(ret); -
200 } -
201 } -
202# else -
203# if _POSIX_VERSION >= 200801L -
204 ret = realpath(entry.nativeFilePath().constData(), (char*)0);
executed (the execution status of this line is deduced): ret = realpath(entry.nativeFilePath().constData(), (char*)0);
-
205# else -
206 ret = (char*)malloc(PATH_MAX + 1); -
207 if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { -
208 const int savedErrno = errno; // errno is checked below, and free() might change it -
209 free(ret); -
210 errno = savedErrno; -
211 ret = 0; -
212 } -
213# endif -
214# endif -
215 if (ret) {
evaluated: ret
TRUEFALSE
yes
Evaluation Count:2207
yes
Evaluation Count:13
13-2207
216 data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
executed (the execution status of this line is deduced): data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
-
217 data.entryFlags |= QFileSystemMetaData::ExistsAttribute;
executed (the execution status of this line is deduced): data.entryFlags |= QFileSystemMetaData::ExistsAttribute;
-
218 QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
executed (the execution status of this line is deduced): QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
-
219 free(ret);
executed (the execution status of this line is deduced): free(ret);
-
220 return QFileSystemEntry(canonicalPath);
executed: return QFileSystemEntry(canonicalPath);
Execution Count:2207
2207
221 } else if (errno == ENOENT) { // file doesn't exist
partially evaluated: (*__errno_location ()) == 2
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
222 data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
executed (the execution status of this line is deduced): data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
-
223 data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute);
executed (the execution status of this line is deduced): data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute);
-
224 return QFileSystemEntry();
executed: return QFileSystemEntry();
Execution Count:13
13
225 } -
226 return entry;
never executed: return entry;
0
227#endif -
228} -
229 -
230//static -
231QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) -
232{ -
233 if (entry.isAbsolute() && entry.isClean()) -
234 return entry; -
235 -
236 QByteArray orig = entry.nativeFilePath(); -
237 QByteArray result; -
238 if (orig.isEmpty() || !orig.startsWith('/')) { -
239 QFileSystemEntry cur(currentPath()); -
240 result = cur.nativeFilePath(); -
241 } -
242 if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) { -
243 if (!result.isEmpty() && !result.endsWith('/')) -
244 result.append('/'); -
245 result.append(orig); -
246 } -
247 -
248 if (result.length() == 1 && result[0] == '/') -
249 return QFileSystemEntry(result, QFileSystemEntry::FromNativePath()); -
250 const bool isDir = result.endsWith('/'); -
251 -
252 /* as long as QDir::cleanPath() operates on a QString we have to convert to a string here. -
253 * ideally we never convert to a string since that loses information. Please fix after -
254 * we get a QByteArray version of QDir::cleanPath() -
255 */ -
256 QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath()); -
257 QString stringVersion = QDir::cleanPath(resultingEntry.filePath()); -
258 if (isDir) -
259 stringVersion.append(QLatin1Char('/')); -
260 return QFileSystemEntry(stringVersion); -
261} -
262 -
263//static -
264QByteArray QFileSystemEngine::id(const QFileSystemEntry &entry) -
265{ -
266 struct stat statResult;
never executed (the execution status of this line is deduced): struct stat statResult;
-
267 if (stat(entry.nativeFilePath().constData(), &statResult)) {
never evaluated: stat(entry.nativeFilePath().constData(), &statResult)
0
268 qErrnoWarning("stat() failed for '%s'", entry.nativeFilePath().constData());
never executed (the execution status of this line is deduced): qErrnoWarning("stat() failed for '%s'", entry.nativeFilePath().constData());
-
269 return QByteArray();
never executed: return QByteArray();
0
270 } -
271 QByteArray result = QByteArray::number(quint64(statResult.st_dev), 16);
never executed (the execution status of this line is deduced): QByteArray result = QByteArray::number(quint64(statResult.st_dev), 16);
-
272 result += ':';
never executed (the execution status of this line is deduced): result += ':';
-
273 result += QByteArray::number(quint64(statResult.st_ino));
never executed (the execution status of this line is deduced): result += QByteArray::number(quint64(statResult.st_ino));
-
274 return result;
never executed: return result;
0
275} -
276 -
277//static -
278QString QFileSystemEngine::resolveUserName(uint userId) -
279{ -
280#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) -
281 int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); -
282 if (size_max == -1) -
283 size_max = 1024; -
284 QVarLengthArray<char, 1024> buf(size_max); -
285#endif -
286 -
287 struct passwd *pw = 0; -
288#if !defined(Q_OS_INTEGRITY) -
289#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) -
290 struct passwd entry; -
291 getpwuid_r(userId, &entry, buf.data(), buf.size(), &pw); -
292#else -
293 pw = getpwuid(userId); -
294#endif -
295#endif -
296 if (pw) -
297 return QFile::decodeName(QByteArray(pw->pw_name)); -
298 return QString(); -
299} -
300 -
301//static -
302QString QFileSystemEngine::resolveGroupName(uint groupId) -
303{ -
304#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) -
305 int size_max = sysconf(_SC_GETPW_R_SIZE_MAX); -
306 if (size_max == -1) -
307 size_max = 1024; -
308 QVarLengthArray<char, 1024> buf(size_max); -
309#endif -
310 -
311 struct group *gr = 0; -
312#if !defined(Q_OS_INTEGRITY) -
313#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) -
314 size_max = sysconf(_SC_GETGR_R_SIZE_MAX); -
315 if (size_max == -1) -
316 size_max = 1024; -
317 buf.resize(size_max); -
318 struct group entry; -
319 // Some large systems have more members than the POSIX max size -
320 // Loop over by doubling the buffer size (upper limit 250k) -
321 for (unsigned size = size_max; size < 256000; size += size) -
322 { -
323 buf.resize(size); -
324 // ERANGE indicates that the buffer was too small -
325 if (!getgrgid_r(groupId, &entry, buf.data(), buf.size(), &gr) -
326 || errno != ERANGE) -
327 break; -
328 } -
329#else -
330 gr = getgrgid(groupId); -
331#endif -
332#endif -
333 if (gr) -
334 return QFile::decodeName(QByteArray(gr->gr_name)); -
335 return QString(); -
336} -
337 -
338#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
339//static -
340QString QFileSystemEngine::bundleName(const QFileSystemEntry &entry) -
341{ -
342 QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(entry.filePath()), -
343 kCFURLPOSIXPathStyle, true); -
344 if (QCFType<CFDictionaryRef> dict = CFBundleCopyInfoDictionaryForURL(url)) { -
345 if (CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) { -
346 if (CFGetTypeID(name) == CFStringGetTypeID()) -
347 return QCFString::toQString((CFStringRef)name); -
348 } -
349 } -
350 return QString(); -
351} -
352#endif -
353 -
354//static -
355bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, -
356 QFileSystemMetaData::MetaDataFlags what) -
357{ -
358#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
359 if (what & QFileSystemMetaData::BundleType) { -
360 if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) -
361 what |= QFileSystemMetaData::DirectoryType; -
362 } -
363# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -
364 if (what & QFileSystemMetaData::HiddenAttribute) { -
365 // Mac OS >= 10.5: st_flags & UF_HIDDEN -
366 what |= QFileSystemMetaData::PosixStatFlags; -
367 } -
368# endif // MAC_OS_X_VERSION_MAX_ALLOWED... -
369#endif // defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
370 -
371 if (what & QFileSystemMetaData::PosixStatFlags) -
372 what |= QFileSystemMetaData::PosixStatFlags; -
373 -
374 if (what & QFileSystemMetaData::ExistsAttribute) { -
375 // FIXME: Would other queries being performed provide this bit? -
376 what |= QFileSystemMetaData::PosixStatFlags; -
377 } -
378 -
379 data.entryFlags &= ~what; -
380 -
381 const char * nativeFilePath; -
382 int nativeFilePathLength; -
383 { -
384 const QByteArray &path = entry.nativeFilePath(); -
385 nativeFilePath = path.constData(); -
386 nativeFilePathLength = path.size(); -
387 Q_UNUSED(nativeFilePathLength); -
388 } -
389 -
390 bool entryExists = true; // innocent until proven otherwise -
391 -
392 QT_STATBUF statBuffer; -
393 bool statBufferValid = false; -
394 if (what & QFileSystemMetaData::LinkType) { -
395 if (QT_LSTAT(nativeFilePath, &statBuffer) == 0) { -
396 if (S_ISLNK(statBuffer.st_mode)) { -
397 data.entryFlags |= QFileSystemMetaData::LinkType; -
398 } else { -
399 statBufferValid = true; -
400 data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags; -
401 } -
402 } else { -
403 entryExists = false; -
404 } -
405 -
406 data.knownFlagsMask |= QFileSystemMetaData::LinkType; -
407 } -
408 -
409 if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) { -
410 if (entryExists && !statBufferValid) -
411 statBufferValid = (QT_STAT(nativeFilePath, &statBuffer) == 0); -
412 -
413 if (statBufferValid) -
414 data.fillFromStatBuf(statBuffer); -
415 else { -
416 entryExists = false; -
417 data.creationTime_ = 0; -
418 data.modificationTime_ = 0; -
419 data.accessTime_ = 0; -
420 data.size_ = 0; -
421 data.userId_ = (uint) -2; -
422 data.groupId_ = (uint) -2; -
423 } -
424 -
425 // reset the mask -
426 data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags -
427 | QFileSystemMetaData::ExistsAttribute; -
428 } -
429 -
430#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
431 if (what & QFileSystemMetaData::AliasType) -
432 { -
433 if (entryExists) { -
434 FSRef fref; -
435 if (FSPathMakeRef((const UInt8 *)nativeFilePath, &fref, NULL) == noErr) { -
436 Boolean isAlias, isFolder; -
437 if (FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr) { -
438 if (isAlias) -
439 data.entryFlags |= QFileSystemMetaData::AliasType; -
440 } -
441 } -
442 } -
443 data.knownFlagsMask |= QFileSystemMetaData::AliasType; -
444 } -
445#endif -
446 -
447 if (what & QFileSystemMetaData::UserPermissions) { -
448 // calculate user permissions -
449 -
450 if (entryExists) { -
451 if (what & QFileSystemMetaData::UserReadPermission) { -
452 if (QT_ACCESS(nativeFilePath, R_OK) == 0) -
453 data.entryFlags |= QFileSystemMetaData::UserReadPermission; -
454 } -
455 if (what & QFileSystemMetaData::UserWritePermission) { -
456 if (QT_ACCESS(nativeFilePath, W_OK) == 0) -
457 data.entryFlags |= QFileSystemMetaData::UserWritePermission; -
458 } -
459 if (what & QFileSystemMetaData::UserExecutePermission) { -
460 if (QT_ACCESS(nativeFilePath, X_OK) == 0) -
461 data.entryFlags |= QFileSystemMetaData::UserExecutePermission; -
462 } -
463 } -
464 data.knownFlagsMask |= (what & QFileSystemMetaData::UserPermissions); -
465 } -
466 -
467 if (what & QFileSystemMetaData::HiddenAttribute -
468 && !data.isHidden()) { -
469 QString fileName = entry.fileName(); -
470 if ((fileName.size() > 0 && fileName.at(0) == QLatin1Char('.')) -
471 || (entryExists && _q_isMacHidden(nativeFilePath))) -
472 data.entryFlags |= QFileSystemMetaData::HiddenAttribute; -
473 data.knownFlagsMask |= QFileSystemMetaData::HiddenAttribute; -
474 } -
475 -
476#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
477 if (what & QFileSystemMetaData::BundleType) { -
478 if (entryExists && data.isDirectory()) { -
479 QCFType<CFStringRef> path = CFStringCreateWithBytes(0, -
480 (const UInt8*)nativeFilePath, nativeFilePathLength, -
481 kCFStringEncodingUTF8, false); -
482 QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, -
483 kCFURLPOSIXPathStyle, true); -
484 -
485 UInt32 type, creator; -
486 if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) -
487 data.entryFlags |= QFileSystemMetaData::BundleType; -
488 } -
489 -
490 data.knownFlagsMask |= QFileSystemMetaData::BundleType; -
491 } -
492#endif -
493 if (!entryExists) { -
494 data.clearFlags(what); -
495 return false; -
496 } -
497 return data.hasFlags(what); -
498} -
499 -
500//static -
501bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool createParents) -
502{ -
503 QString dirName = entry.filePath(); -
504 if (createParents) { -
505 dirName = QDir::cleanPath(dirName); -
506 for (int oldslash = -1, slash=0; slash != -1; oldslash = slash) { -
507 slash = dirName.indexOf(QDir::separator(), oldslash+1); -
508 if (slash == -1) { -
509 if (oldslash == dirName.length()) -
510 break; -
511 slash = dirName.length(); -
512 } -
513 if (slash) { -
514 const QByteArray chunk = QFile::encodeName(dirName.left(slash)); -
515 QT_STATBUF st; -
516 if (QT_STAT(chunk.constData(), &st) != -1) { -
517 if ((st.st_mode & S_IFMT) != S_IFDIR) -
518 return false; -
519 } else if (QT_MKDIR(chunk.constData(), 0777) != 0) { -
520 return false; -
521 } -
522 } -
523 } -
524 return true; -
525 } -
526#if defined(Q_OS_DARWIN) // Mac X doesn't support trailing /'s -
527 if (dirName.endsWith(QLatin1Char('/'))) -
528 dirName.chop(1); -
529#endif -
530 return (QT_MKDIR(QFile::encodeName(dirName).constData(), 0777) == 0); -
531} -
532 -
533//static -
534bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents) -
535{ -
536 if (removeEmptyParents) { -
537 QString dirName = QDir::cleanPath(entry.filePath()); -
538 for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) { -
539 const QByteArray chunk = QFile::encodeName(dirName.left(slash)); -
540 QT_STATBUF st; -
541 if (QT_STAT(chunk.constData(), &st) != -1) { -
542 if ((st.st_mode & S_IFMT) != S_IFDIR) -
543 return false; -
544 if (::rmdir(chunk.constData()) != 0) -
545 return oldslash != 0; -
546 } else { -
547 return false; -
548 } -
549 slash = dirName.lastIndexOf(QDir::separator(), oldslash-1); -
550 } -
551 return true; -
552 } -
553 return rmdir(QFile::encodeName(entry.filePath()).constData()) == 0; -
554} -
555 -
556//static -
557bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) -
558{ -
559 if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) -
560 return true; -
561 error = QSystemError(errno, QSystemError::StandardLibraryError); -
562 return false; -
563} -
564 -
565//static -
566bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) -
567{ -
568 Q_UNUSED(source); -
569 Q_UNUSED(target); -
570 error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented -
571 return false; -
572} -
573 -
574//static -
575bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) -
576{ -
577 if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) -
578 return true; -
579 error = QSystemError(errno, QSystemError::StandardLibraryError); -
580 return false; -
581} -
582 -
583//static -
584bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) -
585{ -
586 if (unlink(entry.nativeFilePath().constData()) == 0) -
587 return true; -
588 error = QSystemError(errno, QSystemError::StandardLibraryError); -
589 return false; -
590 -
591} -
592 -
593//static -
594bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) -
595{ -
596 mode_t mode = 0; -
597 if (permissions & QFile::ReadOwner) -
598 mode |= S_IRUSR; -
599 if (permissions & QFile::WriteOwner) -
600 mode |= S_IWUSR; -
601 if (permissions & QFile::ExeOwner) -
602 mode |= S_IXUSR; -
603 if (permissions & QFile::ReadUser) -
604 mode |= S_IRUSR; -
605 if (permissions & QFile::WriteUser) -
606 mode |= S_IWUSR; -
607 if (permissions & QFile::ExeUser) -
608 mode |= S_IXUSR; -
609 if (permissions & QFile::ReadGroup) -
610 mode |= S_IRGRP; -
611 if (permissions & QFile::WriteGroup) -
612 mode |= S_IWGRP; -
613 if (permissions & QFile::ExeGroup) -
614 mode |= S_IXGRP; -
615 if (permissions & QFile::ReadOther) -
616 mode |= S_IROTH; -
617 if (permissions & QFile::WriteOther) -
618 mode |= S_IWOTH; -
619 if (permissions & QFile::ExeOther) -
620 mode |= S_IXOTH; -
621 -
622 bool success = ::chmod(entry.nativeFilePath().constData(), mode) == 0; -
623 if (success && data) { -
624 data->entryFlags &= ~QFileSystemMetaData::Permissions; -
625 data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions)); -
626 data->knownFlagsMask |= QFileSystemMetaData::Permissions; -
627 } -
628 if (!success) -
629 error = QSystemError(errno, QSystemError::StandardLibraryError); -
630 return success; -
631} -
632 -
633QString QFileSystemEngine::homePath() -
634{ -
635 QString home = QFile::decodeName(qgetenv("HOME"));
executed (the execution status of this line is deduced): QString home = QFile::decodeName(qgetenv("HOME"));
-
636 if (home.isNullisEmpty())
evaluated: home.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:793
1-793
637 home = rootPath();
executed: home = rootPath();
Execution Count:1
1
638 return QDir::cleanPath(home);
executed: return QDir::cleanPath(home);
Execution Count:794
794
639} -
640 -
641QString QFileSystemEngine::rootPath() -
642{ -
643 return QLatin1String("/"); -
644} -
645 -
646QString QFileSystemEngine::tempPath() -
647{ -
648#ifdef QT_UNIX_TEMP_PATH_OVERRIDE -
649 return QLatin1String(QT_UNIX_TEMP_PATH_OVERRIDE); -
650#elif defined(Q_OS_BLACKBERRY) -
651 QString temp = QFile::decodeName(qgetenv("TEMP")); -
652 if (temp.isEmpty()) -
653 temp = QFile::decodeName(qgetenv("TMPDIR")); -
654 -
655 if (temp.isEmpty()) { -
656 qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /tmp."); -
657 temp = QLatin1String("/tmp/"); -
658 } -
659 return QDir::cleanPath(temp); -
660#else -
661 QString temp = QFile::decodeName(qgetenv("TMPDIR")); -
662 if (temp.isEmpty()) -
663 temp = QLatin1String("/tmp/"); -
664 return QDir::cleanPath(temp); -
665#endif -
666} -
667 -
668bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path) -
669{ -
670 int r; -
671 r = QT_CHDIR(path.nativeFilePath().constData()); -
672 return r >= 0; -
673} -
674 -
675QFileSystemEntry QFileSystemEngine::currentPath() -
676{ -
677 QFileSystemEntry result; -
678 QT_STATBUF st; -
679 if (QT_STAT(".", &st) == 0) { -
680#if defined(__GLIBC__) && !defined(PATH_MAX) -
681 char *currentName = ::get_current_dir_name(); -
682 if (currentName) { -
683 result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); -
684 ::free(currentName); -
685 } -
686#else -
687 char currentName[PATH_MAX+1]; -
688 if (::getcwd(currentName, PATH_MAX)) -
689 result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath()); -
690# if defined(QT_DEBUG) -
691 if (result.isEmpty()) -
692 qWarning("QFileSystemEngine::currentPath: getcwd() failed"); -
693# endif -
694#endif -
695 } else { -
696# if defined(QT_DEBUG) -
697 qWarning("QFileSystemEngine::currentPath: stat(\".\") failed"); -
698# endif -
699 } -
700 return result; -
701} -
702QT_END_NAMESPACE -
703 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial