Qt 4.8
Static Public Functions | Static Private Functions | List of all members
QFileSystemEngine Class Reference

#include <qfilesystemengine_p.h>

Static Public Functions

static QFileSystemEntry absoluteName (const QFileSystemEntry &entry)
 
static QString bundleName (const QFileSystemEntry &entry)
 
static QFileSystemEntry canonicalName (const QFileSystemEntry &entry, QFileSystemMetaData &data)
 
static bool copyFile (const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
 
static bool createDirectory (const QFileSystemEntry &entry, bool createParents)
 
static bool createLink (const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
 
static QFileSystemEntry currentPath ()
 
static bool fillMetaData (const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
 
static bool fillMetaData (int fd, QFileSystemMetaData &data)
 
static bool fillMetaData (int fd, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
 
static bool fillMetaData (HANDLE fHandle, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
 
static bool fillPermissions (const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
 
static QFileSystemEntry getLinkTarget (const QFileSystemEntry &link, QFileSystemMetaData &data)
 
static QString homePath ()
 
static bool isCaseSensitive ()
 
static QString nativeAbsoluteFilePath (const QString &path)
 
static QString owner (const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own)
 
static bool removeDirectory (const QFileSystemEntry &entry, bool removeEmptyParents)
 
static bool removeFile (const QFileSystemEntry &entry, QSystemError &error)
 
static bool renameFile (const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
 
static QAbstractFileEngineresolveEntryAndCreateLegacyEngine (QFileSystemEntry &entry, QFileSystemMetaData &data)
 Resolves the entry (see QDir::searchPaths) and returns an engine for it, but never a QFSFileEngine. More...
 
static QString resolveGroupName (const QFileSystemEntry &entry, QFileSystemMetaData &data)
 
static QString resolveGroupName (uint groupId)
 
static QString resolveUserName (const QFileSystemEntry &entry, QFileSystemMetaData &data)
 
static QString resolveUserName (uint userId)
 
static QString rootPath ()
 
static bool setCurrentPath (const QFileSystemEntry &entry)
 
static bool setPermissions (const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data=0)
 
static QString tempPath ()
 
static bool uncListSharesOnServer (const QString &server, QStringList *list)
 

Static Private Functions

static void clearWinStatData (QFileSystemMetaData &data)
 
static QString slowCanonicalized (const QString &path)
 Returns the canonicalized form of path (i. More...
 

Detailed Description

Definition at line 63 of file qfilesystemengine_p.h.

Functions

◆ absoluteName()

QFileSystemEntry QFileSystemEngine::absoluteName ( const QFileSystemEntry entry)
static

Definition at line 236 of file qfilesystemengine_unix.cpp.

Referenced by canonicalName(), QFSFileEngine::fileName(), QFileInfoPrivate::getFileName(), QFSFileEnginePrivate::map(), nativeAbsoluteFilePath(), QTemporaryFileEngine::open(), QDirPrivate::resolveAbsoluteEntry(), and setCloseOnExec().

237 {
238  if (entry.isAbsolute() && entry.isClean())
239  return entry;
240 
241  QByteArray orig = entry.nativeFilePath();
242  QByteArray result;
243  if (orig.isEmpty() || !orig.startsWith('/')) {
245  result = cur.nativeFilePath();
246  }
247  if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) {
248  if (!result.isEmpty() && !result.endsWith('/'))
249  result.append('/');
250  result.append(orig);
251  }
252 
253  if (result.length() == 1 && result[0] == '/')
255  const bool isDir = result.endsWith('/');
256 
257  /* as long as QDir::cleanPath() operates on a QString we have to convert to a string here.
258  * ideally we never convert to a string since that loses information. Please fix after
259  * we get a QByteArray version of QDir::cleanPath()
260  */
261  QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath());
262  QString stringVersion = QDir::cleanPath(resultingEntry.filePath());
263  if (isDir)
264  stringVersion.append(QLatin1Char('/'));
265  return QFileSystemEntry(stringVersion);
266 }
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isAbsolute() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static QFileSystemEntry currentPath()
NativePath nativeFilePath() const
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
int length() const
Same as size().
Definition: qbytearray.h:356
QString & append(QChar c)
Definition: qstring.cpp:1777
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ bundleName()

QString QFileSystemEngine::bundleName ( const QFileSystemEntry entry)
static

Definition at line 331 of file qfilesystemengine_unix.cpp.

Referenced by QFSFileEngine::fileName(), and QFileInfoPrivate::getFileName().

332 {
333  QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(entry.filePath()),
334  kCFURLPOSIXPathStyle, true);
335  if (QCFType<CFDictionaryRef> dict = CFBundleCopyInfoDictionaryForURL(url)) {
336  if (CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) {
337  if (CFGetTypeID(name) == CFStringGetTypeID())
339  }
340  }
341  return QString();
342 }
const struct __CFString * CFStringRef
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * name
const void * CFTypeRef
QString filePath() const

◆ canonicalName()

QFileSystemEntry QFileSystemEngine::canonicalName ( const QFileSystemEntry entry,
QFileSystemMetaData data 
)
static

Definition at line 172 of file qfilesystemengine_unix.cpp.

Referenced by QDir::canonicalPath(), clearWinStatData(), QFSFileEngine::fileName(), QFileInfoPrivate::getFileName(), and QFSFileEnginePrivate::longFileName().

173 {
174  if (entry.isEmpty() || entry.isRoot())
175  return entry;
176 
177 #if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && _POSIX_VERSION < 200809L
178  // realpath(X,0) is not supported
179  Q_UNUSED(data);
180  return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath()));
181 #else
182  char *ret = 0;
183 # if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
184  // When using -mmacosx-version-min=10.4, we get the legacy realpath implementation,
185  // which does not work properly with the realpath(X,0) form. See QTBUG-28282.
187  ret = (char*)malloc(PATH_MAX + 1);
188  if (ret && realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
189  const int savedErrno = errno; // errno is checked below, and free() might change it
190  free(ret);
191  errno = savedErrno;
192  ret = 0;
193  }
194  } else {
195  // on 10.5 we can use FSRef to resolve the file path.
196  QString path = QDir::cleanPath(entry.filePath());
197  FSRef fsref;
198  if (FSPathMakeRef((const UInt8 *)path.toUtf8().data(), &fsref, 0) == noErr) {
199  CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref);
200  CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle);
201  QString ret = QCFString::toQString(canonicalPath);
202  CFRelease(canonicalPath);
203  CFRelease(urlref);
204  return QFileSystemEntry(ret);
205  }
206  }
207 # else
208 # if _POSIX_VERSION >= 200801L
209  ret = realpath(entry.nativeFilePath().constData(), (char*)0);
210 # else
211  ret = (char*)malloc(PATH_MAX + 1);
212  if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
213  const int savedErrno = errno; // errno is checked below, and free() might change it
214  free(ret);
215  errno = savedErrno;
216  ret = 0;
217  }
218 # endif
219 # endif
220  if (ret) {
223  QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
224  free(ret);
225  return QFileSystemEntry(canonicalPath);
226  } else if (errno == ENOENT) { // file doesn't exist
229  return QFileSystemEntry();
230  }
231  return entry;
232 #endif
233 }
const struct __CFString * CFStringRef
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
NativePath nativeFilePath() const
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static QString slowCanonicalized(const QString &path)
Returns the canonicalized form of path (i.
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
#define PATH_MAX
QString filePath() const
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int errno

◆ clearWinStatData()

void QFileSystemEngine::clearWinStatData ( QFileSystemMetaData data)
staticprivate

Definition at line 468 of file qfilesystemengine_win.cpp.

469 {
470  data.size_ = 0;
471  data.fileAttribute_ = 0;
472  data.creationTime_ = FILETIME();
473  data.lastAccessTime_ = FILETIME();
474  data.lastWriteTime_ = FILETIME();
475 }

◆ copyFile()

bool QFileSystemEngine::copyFile ( const QFileSystemEntry source,
const QFileSystemEntry target,
QSystemError error 
)
static

Definition at line 556 of file qfilesystemengine_unix.cpp.

Referenced by QFSFileEngine::copy(), isDirPath(), and QFSFileEnginePrivate::longFileName().

557 {
558  Q_UNUSED(source);
559  Q_UNUSED(target);
560  error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented
561  return false;
562 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ createDirectory()

bool QFileSystemEngine::createDirectory ( const QFileSystemEntry entry,
bool  createParents 
)
static

Definition at line 491 of file qfilesystemengine_unix.cpp.

Referenced by QCoreApplication::init(), isDirPath(), QFSFileEnginePrivate::longFileName(), QFSFileEngine::mkdir(), QDir::mkdir(), and QDir::mkpath().

492 {
493  QString dirName = entry.filePath();
494  if (createParents) {
495  dirName = QDir::cleanPath(dirName);
496  for (int oldslash = -1, slash=0; slash != -1; oldslash = slash) {
497  slash = dirName.indexOf(QDir::separator(), oldslash+1);
498  if (slash == -1) {
499  if (oldslash == dirName.length())
500  break;
501  slash = dirName.length();
502  }
503  if (slash) {
504  QByteArray chunk = QFile::encodeName(dirName.left(slash));
505  QT_STATBUF st;
506  if (QT_STAT(chunk, &st) != -1) {
507  if ((st.st_mode & S_IFMT) != S_IFDIR)
508  return false;
509  } else if (QT_MKDIR(chunk, 0777) != 0) {
510  return false;
511  }
512  }
513  }
514  return true;
515  }
516 #if defined(Q_OS_DARWIN) // Mac X doesn't support trailing /'s
517  if (dirName.endsWith(QLatin1Char('/')))
518  dirName.chop(1);
519 #endif
520  return (QT_MKDIR(QFile::encodeName(dirName), 0777) == 0);
521 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
#define S_IFMT
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
#define S_IFDIR
#define st(var, type, card)
QString filePath() const
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ createLink()

bool QFileSystemEngine::createLink ( const QFileSystemEntry source,
const QFileSystemEntry target,
QSystemError error 
)
static

Definition at line 547 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), and QFSFileEngine::link().

548 {
549  if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0)
550  return true;
552  return false;
553 }
NativePath nativeFilePath() const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int errno

◆ currentPath()

QFileSystemEntry QFileSystemEngine::currentPath ( )
static

Definition at line 665 of file qfilesystemengine_unix.cpp.

Referenced by absoluteName(), QFSFileEngine::currentPath(), QDir::currentPath(), QCoreApplication::init(), isDirPath(), and QFSFileEnginePrivate::longFileName().

666 {
667  QFileSystemEntry result;
668  QT_STATBUF st;
669  if (QT_STAT(".", &st) == 0) {
670 #if defined(__GLIBC__) && !defined(PATH_MAX)
671  char *currentName = ::get_current_dir_name();
672  if (currentName) {
674  ::free(currentName);
675  }
676 #else
677  char currentName[PATH_MAX+1];
678  if (::getcwd(currentName, PATH_MAX)) {
679 #if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM)
680  QByteArray dir(currentName);
681  if (dir.indexOf(':') < dir.indexOf('/'))
682  dir.remove(0, dir.indexOf(':')+1);
683 
684  qstrncpy(currentName, dir.constData(), PATH_MAX);
685 #endif
687  }
688 # if defined(QT_DEBUG)
689  if (result.isEmpty())
690  qWarning("QFSFileEngine::currentPath: getcwd() failed");
691 # endif
692 #endif
693  } else {
694 # if defined(QT_DEBUG)
695  qWarning("QFSFileEngine::currentPath: stat(\".\") failed");
696 # endif
697  }
698  return result;
699 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT void qWarning(const char *,...)
#define PATH_MAX
#define st(var, type, card)
Q_CORE_EXPORT char * qstrncpy(char *dst, const char *src, uint len)

◆ fillMetaData() [1/4]

bool QFileSystemEngine::fillMetaData ( const QFileSystemEntry entry,
QFileSystemMetaData data,
QFileSystemMetaData::MetaDataFlags  what 
)
static

Definition at line 346 of file qfilesystemengine_unix.cpp.

Referenced by _q_checkEntry(), clearWinStatData(), QFileInfo::created(), QFSFileEnginePrivate::doStat(), QDirPrivate::exists(), QFileInfo::exists(), fillMetaData(), getLinkTarget(), QFileInfo::groupId(), QFileInfo::isBundle(), QFileInfo::isDir(), QFileInfo::isExecutable(), QFileInfo::isFile(), QFileInfo::isHidden(), QFileInfo::isReadable(), QDir::isReadable(), QFileInfo::isRoot(), QFileInfo::isSymLink(), QFSFileEnginePrivate::isSymlink(), QFileInfo::isWritable(), QFileInfo::lastModified(), QFileInfo::lastRead(), QFSFileEnginePrivate::longFileName(), QFSFileEnginePrivate::nativeOpen(), openModeToFopenMode(), QFileInfo::ownerId(), QFileInfo::permission(), QFileInfo::permissions(), resolveGroupName(), resolveUserName(), QFileInfo::size(), and tryFindFallback().

348 {
349 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
350  if (what & QFileSystemMetaData::BundleType) {
353  }
354 #endif
355 
356 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) \
357  && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
359  // Mac OS >= 10.5: st_flags & UF_HIDDEN
361  }
362 #endif
363 
366 
368  // FIXME: Would other queries being performed provide this bit?
370  }
371 
372  data.entryFlags &= ~what;
373 
374  const char * nativeFilePath;
375  int nativeFilePathLength;
376  {
377  const QByteArray &path = entry.nativeFilePath();
378  nativeFilePath = path.constData();
379  nativeFilePathLength = path.size();
380  Q_UNUSED(nativeFilePathLength);
381  }
382 
383  bool entryExists = true; // innocent until proven otherwise
384 
385  QT_STATBUF statBuffer;
386  bool statBufferValid = false;
387  if (what & QFileSystemMetaData::LinkType) {
388  if (QT_LSTAT(nativeFilePath, &statBuffer) == 0) {
389  if (S_ISLNK(statBuffer.st_mode)) {
391  } else {
392  statBufferValid = true;
393  data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags;
394  }
395  } else {
396  entryExists = false;
397  }
398 
400  }
401 
402  if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) {
403  if (entryExists && !statBufferValid)
404  statBufferValid = (QT_STAT(nativeFilePath, &statBuffer) == 0);
405 
406  if (statBufferValid)
407  data.fillFromStatBuf(statBuffer);
408  else {
409  entryExists = false;
410  data.creationTime_ = 0;
411  data.modificationTime_ = 0;
412  data.accessTime_ = 0;
413  data.size_ = 0;
414  data.userId_ = (uint) -2;
415  data.groupId_ = (uint) -2;
416  }
417 
418  // reset the mask
419  data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags
421  }
422 
423 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
425  {
426  if (entryExists) {
427  FSRef fref;
428  if (FSPathMakeRef((const UInt8 *)nativeFilePath, &fref, NULL) == noErr) {
429  Boolean isAlias, isFolder;
430  if (FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr) {
431  if (isAlias)
433  }
434  }
435  }
437  }
438 #endif
439 
441  // calculate user permissions
442 
443  if (entryExists) {
445  if (QT_ACCESS(nativeFilePath, R_OK) == 0)
446  data.entryFlags |= QFileSystemMetaData::UserReadPermission;
447  }
449  if (QT_ACCESS(nativeFilePath, W_OK) == 0)
450  data.entryFlags |= QFileSystemMetaData::UserWritePermission;
451  }
453  if (QT_ACCESS(nativeFilePath, X_OK) == 0)
454  data.entryFlags |= QFileSystemMetaData::UserExecutePermission;
455  }
456  }
458  }
459 
460  if (what & QFileSystemMetaData::HiddenAttribute
461  && !data.isHidden()) {
462  QString fileName = entry.fileName();
463  if ((fileName.size() > 0 && fileName.at(0) == QLatin1Char('.'))
464  || (entryExists && _q_isMacHidden(nativeFilePath)))
467  }
468 
469 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
470  if (what & QFileSystemMetaData::BundleType) {
471  if (entryExists && data.isDirectory()) {
472  QCFType<CFStringRef> path = CFStringCreateWithBytes(0,
473  (const UInt8*)nativeFilePath, nativeFilePathLength,
474  kCFStringEncodingUTF8, false);
475  QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path,
476  kCFURLPOSIXPathStyle, true);
477 
478  UInt32 type, creator;
479  if (CFBundleGetPackageInfoInDirectory(url, &type, &creator))
481  }
482 
484  }
485 #endif
486 
487  return data.hasFlags(what);
488 }
int type
Definition: qmetatype.cpp:239
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
NativePath nativeFilePath() const
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
QString fileName() const
unsigned int uint
Definition: qglobal.h:996
bool hasFlags(MetaDataFlags flags) const
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static bool _q_isMacHidden(const char *nativePath)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
#define S_ISLNK(x)
Definition: qzip.cpp:69
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void fillFromStatBuf(const QT_STATBUF &statBuffer)

◆ fillMetaData() [2/4]

bool QFileSystemEngine::fillMetaData ( int  fd,
QFileSystemMetaData data 
)
static

Definition at line 227 of file qfilesystemengine.cpp.

228 {
229  data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags;
231 
232  QT_STATBUF statBuffer;
233  if (QT_FSTAT(fd, &statBuffer) == 0) {
234  data.fillFromStatBuf(statBuffer);
235  return true;
236  }
237 
238  return false;
239 }
void fillFromStatBuf(const QT_STATBUF &statBuffer)

◆ fillMetaData() [3/4]

static bool QFileSystemEngine::fillMetaData ( int  fd,
QFileSystemMetaData data,
QFileSystemMetaData::MetaDataFlags  what 
)
static

◆ fillMetaData() [4/4]

bool QFileSystemEngine::fillMetaData ( HANDLE  fHandle,
QFileSystemMetaData data,
QFileSystemMetaData::MetaDataFlags  what 
)
static

Definition at line 819 of file qfilesystemengine_win.cpp.

821 {
822  data.entryFlags &= ~what;
823  clearWinStatData(data);
824  BY_HANDLE_FILE_INFORMATION fileInfo;
826  if (GetFileInformationByHandle(fHandle , &fileInfo)) {
827  data.fillFromFindInfo(fileInfo);
828  }
829  SetErrorMode(oldmode);
830  return data.hasFlags(what);
831 }
void fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo)
#define SEM_FAILCRITICALERRORS
bool hasFlags(MetaDataFlags flags) const
#define SetErrorMode(a)
#define SEM_NOOPENFILEERRORBOX
static void clearWinStatData(QFileSystemMetaData &data)

◆ fillPermissions()

bool QFileSystemEngine::fillPermissions ( const QFileSystemEntry entry,
QFileSystemMetaData data,
QFileSystemMetaData::MetaDataFlags  what 
)
static

Definition at line 625 of file qfilesystemengine_win.cpp.

627 {
628 #if !defined(QT_NO_LIBRARY)
630  resolveLibs();
631  if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) {
632  enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 };
633 
634  QString fname = entry.filePath();
635  PSID pOwner = 0;
636  PSID pGroup = 0;
637  PACL pDacl;
638  PSECURITY_DESCRIPTOR pSD;
639  DWORD res = ptrGetNamedSecurityInfoW((wchar_t*)fname.utf16(), SE_FILE_OBJECT,
640  OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
641  &pOwner, &pGroup, &pDacl, 0, &pSD);
642  if(res == ERROR_SUCCESS) {
643  ACCESS_MASK access_mask;
644  TRUSTEE_W trustee;
645  if (what & QFileSystemMetaData::UserPermissions) { // user
647  if(ptrGetEffectiveRightsFromAclW(pDacl, &currentUserTrusteeW, &access_mask) != ERROR_SUCCESS)
648  access_mask = (ACCESS_MASK)-1;
649  if(access_mask & ReadMask)
651  if(access_mask & WriteMask)
653  if(access_mask & ExecMask)
655  }
656  if (what & QFileSystemMetaData::OwnerPermissions) { // owner
658  ptrBuildTrusteeWithSidW(&trustee, pOwner);
659  if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
660  access_mask = (ACCESS_MASK)-1;
661  if(access_mask & ReadMask)
663  if(access_mask & WriteMask)
665  if(access_mask & ExecMask)
667  }
668  if (what & QFileSystemMetaData::GroupPermissions) { // group
670  ptrBuildTrusteeWithSidW(&trustee, pGroup);
671  if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
672  access_mask = (ACCESS_MASK)-1;
673  if(access_mask & ReadMask)
675  if(access_mask & WriteMask)
677  if(access_mask & ExecMask)
679  }
680  if (what & QFileSystemMetaData::OtherPermissions) { // other (world)
682  if(ptrGetEffectiveRightsFromAclW(pDacl, &worldTrusteeW, &access_mask) != ERROR_SUCCESS)
683  access_mask = (ACCESS_MASK)-1; // ###
684  if(access_mask & ReadMask)
686  if(access_mask & WriteMask)
688  if(access_mask & ExecMask)
690  }
691  LocalFree(pSD);
692  }
693  }
694  } else
695 #endif
696  {
697  //### what to do with permissions if we don't use NTFS
698  // for now just add all permissions and what about exe missions ??
699  // also qt_ntfs_permission_lookup is now not set by default ... should it ?
703 
704  if (!(data.fileAttribute_ & FILE_ATTRIBUTE_READONLY)) {
708  }
709 
710  QString fname = entry.filePath();
711  QString ext = fname.right(4).toLower();
712  if (data.isDirectory() ||
713  ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") ||
714  ext == QLatin1String(".pif") || ext == QLatin1String(".cmd")) {
717  }
718  data.knownFlagsMask |= QFileSystemMetaData::OwnerPermissions | QFileSystemMetaData::GroupPermissions
719  | QFileSystemMetaData::OtherPermissions | QFileSystemMetaData::UserExecutePermission;
720  // calculate user permissions
722  if (::_waccess((wchar_t*)entry.nativeFilePath().utf16(), R_OK) == 0)
725  }
727  if (::_waccess((wchar_t*)entry.nativeFilePath().utf16(), W_OK) == 0)
730  }
731  }
732 
733  return data.hasFlags(what);
734 }
#define _waccess(a, b)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
The QString class provides a Unicode character string.
Definition: qstring.h:83
NativePath nativeFilePath() const
Q_CORE_EXPORT int qt_ntfs_permission_lookup
static void resolveLibs()
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
bool hasFlags(MetaDataFlags flags) const
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString filePath() const
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ getLinkTarget()

QFileSystemEntry QFileSystemEngine::getLinkTarget ( const QFileSystemEntry link,
QFileSystemMetaData data 
)
static

Definition at line 96 of file qfilesystemengine_unix.cpp.

Referenced by clearWinStatData(), QFSFileEngine::fileName(), QFileInfoPrivate::getFileName(), and QFSFileEnginePrivate::longFileName().

97 {
98 #if defined(__GLIBC__) && !defined(PATH_MAX)
99 #define PATH_CHUNK_SIZE 256
100  char *s = 0;
101  int len = -1;
102  int size = PATH_CHUNK_SIZE;
103 
104  while (1) {
105  s = (char *) ::realloc(s, size);
106  Q_CHECK_PTR(s);
107  len = ::readlink(link.nativeFilePath().constData(), s, size);
108  if (len < 0) {
109  ::free(s);
110  break;
111  }
112  if (len < size) {
113  break;
114  }
115  size *= 2;
116  }
117 #else
118  char s[PATH_MAX+1];
119  int len = readlink(link.nativeFilePath().constData(), s, PATH_MAX);
120 #endif
121  if (len > 0) {
122  QString ret;
125  if (data.isDirectory() && s[0] != '/') {
126  QDir parent(link.filePath());
127  parent.cdUp();
128  ret = parent.path();
129  if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/')))
130  ret += QLatin1Char('/');
131  }
132  s[len] = '\0';
133  ret += QFile::decodeName(QByteArray(s));
134 #if defined(__GLIBC__) && !defined(PATH_MAX)
135  ::free(s);
136 #endif
137 
138  if (!ret.startsWith(QLatin1Char('/'))) {
139  if (link.filePath().startsWith(QLatin1Char('/'))) {
140  ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/')))
141  + QLatin1Char('/'));
142  } else {
143  ret.prepend(QDir::currentPath() + QLatin1Char('/'));
144  }
145  }
146  ret = QDir::cleanPath(ret);
147  if (ret.size() > 1 && ret.endsWith(QLatin1Char('/')))
148  ret.chop(1);
149  return QFileSystemEntry(ret);
150  }
151 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
152  {
153  FSRef fref;
154  if (FSPathMakeRef((const UInt8 *)QFile::encodeName(QDir::cleanPath(link.filePath())).data(), &fref, 0) == noErr) {
155  // TODO get the meta data info from the QFileSystemMetaData object
156  Boolean isAlias, isFolder;
157  if (FSResolveAliasFile(&fref, true, &isFolder, &isAlias) == noErr && isAlias) {
158  AliasHandle alias;
159  if (FSNewAlias(0, &fref, &alias) == noErr && alias) {
160  QCFString cfstr;
161  if (FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr)
162  return QFileSystemEntry(QCFString::toQString(cfstr));
163  }
164  }
165  }
166  }
167 #endif
168  return QFileSystemEntry();
169 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString & prepend(QChar c)
Definition: qstring.h:261
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
NativePath nativeFilePath() const
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
bool cdUp()
Changes directory by moving one directory up from the QDir&#39;s current directory.
Definition: qdir.cpp:937
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool hasFlags(MetaDataFlags flags) const
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
#define PATH_MAX
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
QString filePath() const
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ homePath()

QString QFileSystemEngine::homePath ( )
static

Definition at line 623 of file qfilesystemengine_unix.cpp.

Referenced by QFSFileEngine::homePath(), QDir::homePath(), isDirPath(), and QFSFileEnginePrivate::longFileName().

624 {
625  QString home = QFile::decodeName(qgetenv("HOME"));
626  if (home.isEmpty())
627  home = rootPath();
628  return QDir::cleanPath(home);
629 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082

◆ isCaseSensitive()

bool QFileSystemEngine::isCaseSensitive ( )
static

Definition at line 90 of file qfilesystemengine_unix.cpp.

Referenced by clearWinStatData(), QFileInfo::operator==(), and QDir::operator==().

91 {
92  return true;
93 }

◆ nativeAbsoluteFilePath()

QString QFileSystemEngine::nativeAbsoluteFilePath ( const QString path)
static

Definition at line 510 of file qfilesystemengine_win.cpp.

Referenced by QFSFileEnginePrivate::longFileName().

511 {
512  // can be //server or //server/share
513  QString absPath;
514 #if !defined(Q_OS_WINCE)
515  QVarLengthArray<wchar_t, MAX_PATH> buf(qMax(MAX_PATH, path.size() + 1));
516  wchar_t *fileName = 0;
517  DWORD retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
518  if (retLen > (DWORD)buf.size()) {
519  buf.resize(retLen);
520  retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
521  }
522  if (retLen != 0)
523  absPath = QString::fromWCharArray(buf.data(), retLen);
524 #else
525  if (path.startsWith(QLatin1Char('/')) || path.startsWith(QLatin1Char('\\')))
526  absPath = QDir::toNativeSeparators(path);
527  else
529 #endif
530  // This is really ugly, but GetFullPathName strips off whitespace at the end.
531  // If you for instance write ". " in the lineedit of QFileDialog,
532  // (which is an invalid filename) this function will strip the space off and viola,
533  // the file is later reported as existing. Therefore, we re-add the whitespace that
534  // was at the end of path in order to keep the filename invalid.
535  if (!path.isEmpty() && path.at(path.size() - 1) == QLatin1Char(' '))
536  absPath.append(QLatin1Char(' '));
537  return absPath;
538 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString qfsPrivateCurrentDir
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
QString & append(QChar c)
Definition: qstring.cpp:1777
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ owner()

QString QFileSystemEngine::owner ( const QFileSystemEntry entry,
QAbstractFileEngine::FileOwner  own 
)
static

Definition at line 575 of file qfilesystemengine_win.cpp.

Referenced by QFSFileEnginePrivate::longFileName(), resolveGroupName(), and resolveUserName().

576 {
577  QString name;
578 #if !defined(QT_NO_LIBRARY)
579  extern int qt_ntfs_permission_lookup;
580  if((qt_ntfs_permission_lookup > 0) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)) {
581  resolveLibs();
582  if (ptrGetNamedSecurityInfoW && ptrLookupAccountSidW) {
583  PSID pOwner = 0;
584  PSECURITY_DESCRIPTOR pSD;
585  if (ptrGetNamedSecurityInfoW((wchar_t*)entry.nativeFilePath().utf16(), SE_FILE_OBJECT,
586  own == QAbstractFileEngine::OwnerGroup ? GROUP_SECURITY_INFORMATION : OWNER_SECURITY_INFORMATION,
587  own == QAbstractFileEngine::OwnerUser ? &pOwner : 0, own == QAbstractFileEngine::OwnerGroup ? &pOwner : 0,
588  0, 0, &pSD) == ERROR_SUCCESS) {
589  DWORD lowner = 64;
590  DWORD ldomain = 64;
592  QVarLengthArray<wchar_t, 64> domain(ldomain);
593  SID_NAME_USE use = SidTypeUnknown;
594  // First call, to determine size of the strings (with '\0').
595  if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
596  (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
597  if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
598  if (lowner > (DWORD)owner.size())
599  owner.resize(lowner);
600  if (ldomain > (DWORD)domain.size())
601  domain.resize(ldomain);
602  // Second call, try on resized buf-s
603  if (!ptrLookupAccountSidW(NULL, pOwner, (LPWSTR)owner.data(), &lowner,
604  (LPWSTR)domain.data(), &ldomain, (SID_NAME_USE*)&use)) {
605  lowner = 0;
606  }
607  } else {
608  lowner = 0;
609  }
610  }
611  if (lowner != 0)
613  LocalFree(pSD);
614  }
615  }
616  }
617 #else
618  Q_UNUSED(entry);
619  Q_UNUSED(own);
620 #endif
621  return name;
622 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
The QString class provides a Unicode character string.
Definition: qstring.h:83
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
NativePath nativeFilePath() const
Q_CORE_EXPORT int qt_ntfs_permission_lookup
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const char * name
static void resolveLibs()
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ removeDirectory()

bool QFileSystemEngine::removeDirectory ( const QFileSystemEntry entry,
bool  removeEmptyParents 
)
static

Definition at line 524 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), QFSFileEnginePrivate::longFileName(), QFSFileEngine::rmdir(), QDir::rmdir(), and QDir::rmpath().

525 {
526  if (removeEmptyParents) {
527  QString dirName = QDir::cleanPath(entry.filePath());
528  for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) {
529  QByteArray chunk = QFile::encodeName(dirName.left(slash));
530  QT_STATBUF st;
531  if (QT_STAT(chunk, &st) != -1) {
532  if ((st.st_mode & S_IFMT) != S_IFDIR)
533  return false;
534  if (::rmdir(chunk) != 0)
535  return oldslash != 0;
536  } else {
537  return false;
538  }
539  slash = dirName.lastIndexOf(QDir::separator(), oldslash-1);
540  }
541  return true;
542  }
543  return rmdir(QFile::encodeName(entry.filePath())) == 0;
544 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
#define S_IFMT
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
#define S_IFDIR
#define st(var, type, card)
QString filePath() const
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528

◆ removeFile()

bool QFileSystemEngine::removeFile ( const QFileSystemEntry entry,
QSystemError error 
)
static

Definition at line 574 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), QFSFileEnginePrivate::longFileName(), and QFSFileEngine::remove().

575 {
576  if (unlink(entry.nativeFilePath().constData()) == 0)
577  return true;
579  return false;
580 
581 }
NativePath nativeFilePath() const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int errno

◆ renameFile()

bool QFileSystemEngine::renameFile ( const QFileSystemEntry source,
const QFileSystemEntry target,
QSystemError error 
)
static

Definition at line 565 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), QFSFileEnginePrivate::longFileName(), and QFSFileEngine::rename().

566 {
567  if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0)
568  return true;
570  return false;
571 }
NativePath nativeFilePath() const
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int errno

◆ resolveEntryAndCreateLegacyEngine()

QAbstractFileEngine * QFileSystemEngine::resolveEntryAndCreateLegacyEngine ( QFileSystemEntry entry,
QFileSystemMetaData data 
)
static

Resolves the entry (see QDir::searchPaths) and returns an engine for it, but never a QFSFileEngine.

Warning
This function is not part of the public interface.

Returns a file engine that can be used to access the entry. Returns 0 if QFileSystemEngine API should be used to query and interact with the file system object.

Definition at line 209 of file qfilesystemengine.cpp.

Referenced by QAbstractFileEngine::create(), QDirPrivate::initFileEngine(), and QDirIteratorPrivate::QDirIteratorPrivate().

210  {
211  QFileSystemEntry copy = entry;
212  QAbstractFileEngine *engine = 0;
213 
214  if (_q_resolveEntryAndCreateLegacyEngine_recursive(copy, data, engine))
215  // Reset entry to resolved copy.
216  entry = copy;
217  else
218  data.clear();
219 
220  return engine;
221 }
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &entry, QFileSystemMetaData &data, QAbstractFileEngine *&engine, bool resolvingEntry=false)

◆ resolveGroupName() [1/2]

QString QFileSystemEngine::resolveGroupName ( const QFileSystemEntry entry,
QFileSystemMetaData data 
)
static

Definition at line 435 of file qfilesystemengine.cpp.

Referenced by QFileInfoPrivate::getFileOwner(), and QFSFileEngine::owner().

436 {
437 #if defined (Q_OS_SYMBIAN)
438  Q_UNUSED(entry);
439  Q_UNUSED(metaData);
440  return QString();
441 #elif defined(Q_OS_WIN)
442  Q_UNUSED(metaData);
444 #else //(Q_OS_UNIX)
445  if (!metaData.hasFlags(QFileSystemMetaData::GroupId))
447  return resolveGroupName(metaData.groupId());
448 #endif
449 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ resolveGroupName() [2/2]

QString QFileSystemEngine::resolveGroupName ( uint  groupId)
static

Definition at line 293 of file qfilesystemengine_unix.cpp.

294 {
295 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
296  int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
297  if (size_max == -1)
298  size_max = 1024;
299  QVarLengthArray<char, 1024> buf(size_max);
300 #endif
301 
302  struct group *gr = 0;
303 #if !defined(Q_OS_INTEGRITY)
304 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS)
305  size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
306  if (size_max == -1)
307  size_max = 1024;
308  buf.resize(size_max);
309  struct group entry;
310  // Some large systems have more members than the POSIX max size
311  // Loop over by doubling the buffer size (upper limit 250k)
312  for (unsigned size = size_max; size < 256000; size += size)
313  {
314  buf.resize(size);
315  // ERANGE indicates that the buffer was too small
316  if (!getgrgid_r(groupId, &entry, buf.data(), buf.size(), &gr)
317  || errno != ERANGE)
318  break;
319  }
320 #else
321  gr = getgrgid(groupId);
322 #endif
323 #endif
324  if (gr)
325  return QFile::decodeName(QByteArray(gr->gr_name));
326  return QString();
327 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
int errno

◆ resolveUserName() [1/2]

QString QFileSystemEngine::resolveUserName ( const QFileSystemEntry entry,
QFileSystemMetaData data 
)
static

Definition at line 418 of file qfilesystemengine.cpp.

Referenced by QFileInfoPrivate::getFileOwner(), and QFSFileEngine::owner().

419 {
420 #if defined (Q_OS_SYMBIAN)
421  Q_UNUSED(entry);
422  Q_UNUSED(metaData);
423  return QString();
424 #elif defined(Q_OS_WIN)
425  Q_UNUSED(metaData);
427 #else //(Q_OS_UNIX)
428  if (!metaData.hasFlags(QFileSystemMetaData::UserId))
430  return resolveUserName(metaData.userId());
431 #endif
432 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ resolveUserName() [2/2]

QString QFileSystemEngine::resolveUserName ( uint  userId)
static

Definition at line 269 of file qfilesystemengine_unix.cpp.

270 {
271 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
272  int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
273  if (size_max == -1)
274  size_max = 1024;
275  QVarLengthArray<char, 1024> buf(size_max);
276 #endif
277 
278  struct passwd *pw = 0;
279 #if !defined(Q_OS_INTEGRITY)
280 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS)
281  struct passwd entry;
282  getpwuid_r(userId, &entry, buf.data(), buf.size(), &pw);
283 #else
284  pw = getpwuid(userId);
285 #endif
286 #endif
287  if (pw)
288  return QFile::decodeName(QByteArray(pw->pw_name));
289  return QString();
290 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552

◆ rootPath()

QString QFileSystemEngine::rootPath ( )
static

Definition at line 631 of file qfilesystemengine_unix.cpp.

Referenced by homePath(), isDirPath(), QFSFileEnginePrivate::longFileName(), QFSFileEngine::rootPath(), and QDir::rootPath().

632 {
633  return QLatin1String("/");
634 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ setCurrentPath()

bool QFileSystemEngine::setCurrentPath ( const QFileSystemEntry entry)
static

Definition at line 658 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), QFSFileEnginePrivate::longFileName(), QDir::setCurrent(), and QFSFileEngine::setCurrentPath().

659 {
660  int r;
661  r = QT_CHDIR(path.nativeFilePath());
662  return r >= 0;
663 }

◆ setPermissions()

bool QFileSystemEngine::setPermissions ( const QFileSystemEntry entry,
QFile::Permissions  permissions,
QSystemError error,
QFileSystemMetaData data = 0 
)
static

Definition at line 584 of file qfilesystemengine_unix.cpp.

Referenced by isDirPath(), QFSFileEnginePrivate::longFileName(), and QFSFileEngine::setPermissions().

585 {
586  mode_t mode = 0;
587  if (permissions & QFile::ReadOwner)
588  mode |= S_IRUSR;
589  if (permissions & QFile::WriteOwner)
590  mode |= S_IWUSR;
591  if (permissions & QFile::ExeOwner)
592  mode |= S_IXUSR;
593  if (permissions & QFile::ReadUser)
594  mode |= S_IRUSR;
595  if (permissions & QFile::WriteUser)
596  mode |= S_IWUSR;
597  if (permissions & QFile::ExeUser)
598  mode |= S_IXUSR;
599  if (permissions & QFile::ReadGroup)
600  mode |= S_IRGRP;
601  if (permissions & QFile::WriteGroup)
602  mode |= S_IWGRP;
603  if (permissions & QFile::ExeGroup)
604  mode |= S_IXGRP;
605  if (permissions & QFile::ReadOther)
606  mode |= S_IROTH;
607  if (permissions & QFile::WriteOther)
608  mode |= S_IWOTH;
609  if (permissions & QFile::ExeOther)
610  mode |= S_IXOTH;
611 
612  bool success = ::chmod(entry.nativeFilePath().constData(), mode) == 0;
613  if (success && data) {
614  data->entryFlags &= ~QFileSystemMetaData::Permissions;
615  data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions));
617  }
618  if (!success)
620  return success;
621 }
#define S_IWOTH
Definition: qzip.cpp:83
#define S_IRGRP
Definition: qzip.cpp:79
#define S_IXGRP
Definition: qzip.cpp:81
#define S_IRUSR
Definition: qzip.cpp:71
#define S_IXUSR
Definition: qzip.cpp:77
NativePath nativeFilePath() const
int mode_t
#define S_IXOTH
Definition: qzip.cpp:84
#define S_IROTH
Definition: qzip.cpp:82
unsigned int uint
Definition: qglobal.h:996
#define S_IWGRP
Definition: qzip.cpp:80
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
int errno
#define S_IWUSR
Definition: qzip.cpp:74

◆ slowCanonicalized()

QString QFileSystemEngine::slowCanonicalized ( const QString path)
staticprivate

Returns the canonicalized form of path (i.

Warning
This function is not part of the public interface.

e., with all symlinks resolved, and all redundant path elements removed.

Definition at line 62 of file qfilesystemengine.cpp.

Referenced by canonicalName().

63 {
64  if (path.isEmpty())
65  return path;
66 
67  QFileInfo fi;
68  const QChar slash(QLatin1Char('/'));
69  QString tmpPath = path;
70  int separatorPos = 0;
71  QSet<QString> nonSymlinks;
72  QSet<QString> known;
73 
74  known.insert(path);
75  do {
76 #ifdef Q_OS_WIN
77  if (separatorPos == 0) {
78  if (tmpPath.size() >= 2 && tmpPath.at(0) == slash && tmpPath.at(1) == slash) {
79  // UNC, skip past the first two elements
80  separatorPos = tmpPath.indexOf(slash, 2);
81  } else if (tmpPath.size() >= 3 && tmpPath.at(1) == QLatin1Char(':') && tmpPath.at(2) == slash) {
82  // volume root, skip since it can not be a symlink
83  separatorPos = 2;
84  }
85  }
86  if (separatorPos != -1)
87 #endif
88  separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
89  QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
90  if (
91 #ifdef Q_OS_SYMBIAN
92  // Symbian doesn't support directory symlinks, so do not check for link unless we
93  // are handling the last path element. This not only slightly improves performance,
94  // but also saves us from lot of unnecessary platform security check failures
95  // when dealing with files under *:/private directories.
96  separatorPos == -1 &&
97 #endif
98  !nonSymlinks.contains(prefix)) {
99  fi.setFile(prefix);
100  if (fi.isSymLink()) {
101  QString target = fi.symLinkTarget();
102  if(QFileInfo(target).isRelative())
103  target = fi.absolutePath() + slash + target;
104  if (separatorPos != -1) {
105  if (fi.isDir() && !target.endsWith(slash))
106  target.append(slash);
107  target.append(tmpPath.mid(separatorPos));
108  }
109  tmpPath = QDir::cleanPath(target);
110  separatorPos = 0;
111 
112  if (known.contains(tmpPath))
113  return QString();
114  known.insert(tmpPath);
115  } else {
116  nonSymlinks.insert(prefix);
117  }
118  }
119  } while (separatorPos != -1);
120 
121  return QDir::cleanPath(tmpPath);
122 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool contains(const T &value) const
Definition: qset.h:91
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
const_iterator insert(const T &value)
Definition: qset.h:179
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString & append(QChar c)
Definition: qstring.cpp:1777
QString symLinkTarget() const
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to...
Definition: qfileinfo.h:121
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ tempPath()

QString QFileSystemEngine::tempPath ( )
static

Definition at line 636 of file qfilesystemengine_unix.cpp.

Referenced by QCoreApplication::init(), isDirPath(), QFSFileEnginePrivate::longFileName(), QFSFileEngine::tempPath(), and QDir::tempPath().

637 {
638 #ifdef QT_UNIX_TEMP_PATH_OVERRIDE
639  return QLatin1String(QT_UNIX_TEMP_PATH_OVERRIDE);
640 #elif defined(Q_OS_BLACKBERRY)
641  QString temp = QFile::decodeName(qgetenv("TEMP"));
642  if (temp.isEmpty())
643  temp = QFile::decodeName(qgetenv("TMPDIR"));
644 
645  if (temp.isEmpty()) {
646  qWarning("Neither the TEMP nor the TMPDIR environment variable is set, falling back to /tmp.");
647  temp = QLatin1String("/tmp/");
648  }
649  return QDir::cleanPath(temp);
650 #else
651  QString temp = QFile::decodeName(qgetenv("TMPDIR"));
652  if (temp.isEmpty())
653  temp = QLatin1String("/tmp/");
654  return QDir::cleanPath(temp);
655 #endif
656 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082

◆ uncListSharesOnServer()

bool QFileSystemEngine::uncListSharesOnServer ( const QString server,
QStringList list 
)
static

Definition at line 445 of file qfilesystemengine_win.cpp.

Referenced by uncShareExists().

446 {
447  if (resolveUNCLibs()) {
448  SHARE_INFO_1 *BufPtr, *p;
449  DWORD res;
450  DWORD er = 0, tr = 0, resume = 0, i;
451  do {
452  res = ptrNetShareEnum((wchar_t*)server.utf16(), 1, (LPBYTE *)&BufPtr, DWORD(-1), &er, &tr, &resume);
453  if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) {
454  p = BufPtr;
455  for (i = 1; i <= er; ++i) {
456  if (list && p->shi1_type == 0)
458  p++;
459  }
460  }
461  ptrNetApiBufferFree(BufPtr);
462  } while (res == ERROR_MORE_DATA);
463  return res == ERROR_SUCCESS;
464  }
465  return false;
466 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static PtrNetApiBufferFree ptrNetApiBufferFree
static bool resolveUNCLibs()
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static PtrNetShareEnum ptrNetShareEnum
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

The documentation for this class was generated from the following files: