本文整理汇总了C++中QFileSystemMetaData类的典型用法代码示例。如果您正苦于以下问题:C++ QFileSystemMetaData类的具体用法?C++ QFileSystemMetaData怎么用?C++ QFileSystemMetaData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFileSystemMetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openModeToFopenMode
/*!
\internal
Returns the stdlib open string corresponding to a QIODevice::OpenMode.
*/
static inline QByteArray openModeToFopenMode(QIODevice::OpenMode flags, const QFileSystemEntry &fileEntry,
QFileSystemMetaData &metaData)
{
QByteArray mode;
if ((flags & QIODevice::ReadOnly) && !(flags & QIODevice::Truncate)) {
mode = "rb";
if (flags & QIODevice::WriteOnly) {
metaData.clearFlags(QFileSystemMetaData::FileType);
if (!fileEntry.isEmpty()
&& QFileSystemEngine::fillMetaData(fileEntry, metaData, QFileSystemMetaData::FileType)
&& metaData.isFile()) {
mode += '+';
} else {
mode = "wb+";
}
}
} else if (flags & QIODevice::WriteOnly) {
mode = "wb";
if (flags & QIODevice::ReadOnly)
mode += '+';
}
if (flags & QIODevice::Append) {
mode = "ab";
if (flags & QIODevice::ReadOnly)
mode += '+';
}
#if defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0207
// must be glibc >= 2.7
mode += 'e';
#endif
return mode;
}
示例2: defined
//static
QString QFileSystemEngine::resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
{
#if defined(Q_OS_WIN)
Q_UNUSED(metaData);
return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerGroup);
#else //(Q_OS_UNIX)
if (!metaData.hasFlags(QFileSystemMetaData::GroupId))
QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::GroupId);
return resolveGroupName(metaData.groupId());
#endif
}
示例3: _q_checkEntry
static inline bool _q_checkEntry(QFileSystemEntry &entry, QFileSystemMetaData &data, bool resolvingEntry)
{
if (resolvingEntry) {
if (!QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute)
|| !data.exists()) {
data.clear();
return false;
}
}
return true;
}
示例4: QFileInfo
/*!
\since 5.2
Returns \c true if the \a file exists; otherwise returns \c false.
\note If \a file is a symlink that points to a non-existing
file, false is returned.
\note Using this function is faster than using
\c QFileInfo(file).exists() for file system access.
*/
bool QFileInfo::exists(const QString &file)
{
QFileSystemEntry entry(file);
QFileSystemMetaData data;
QAbstractFileEngine *engine =
QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data);
// Expensive fallback to non-QFileSystemEngine implementation
if (engine)
return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
return data.exists();
}
示例5: defined
//static
QString QFileSystemEngine::resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
{
#if defined (Q_OS_SYMBIAN)
Q_UNUSED(entry);
Q_UNUSED(metaData);
return QString();
#elif defined(Q_OS_WIN)
Q_UNUSED(metaData);
return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerUser);
#else //(Q_OS_UNIX)
if (!metaData.hasFlags(QFileSystemMetaData::UserId))
QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::UserId);
return resolveUserName(metaData.userId());
#endif
}
示例6: absoluteName
//static
QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
{
if (entry.isEmpty() || entry.isRoot())
return entry;
QFileSystemEntry result = absoluteName(entry);
if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute))
fillMetaData(result, data, QFileSystemMetaData::ExistsAttribute);
if (!data.exists()) {
// file doesn't exist
return QFileSystemEntry();
} else {
return result;
}
}
示例7: defined
QT_BEGIN_NAMESPACE
#if defined(Q_OS_DARWIN)
static inline bool hasResourcePropertyFlag(const QFileSystemMetaData &data,
const QFileSystemEntry &entry,
CFStringRef key)
{
QCFString path = CFStringCreateWithFileSystemRepresentation(0,
entry.nativeFilePath().constData());
if (!path)
return false;
QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle,
data.hasFlags(QFileSystemMetaData::DirectoryType));
if (!url)
return false;
CFBooleanRef value;
if (CFURLCopyResourcePropertyForKey(url, key, &value, NULL)) {
if (value == kCFBooleanTrue)
return true;
}
return false;
}
示例8: advance
bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
{
//1st time, lastError is result of dirHandle.Open(), entries.Count() is 0 and entryIndex is -1 so initial read is triggered
//subsequent times, read is triggered each time we reach the end of the entry list
//final time, lastError is KErrEof so we don't need to read anymore.
++entryIndex;
if (lastError == KErrNone && entryIndex >= entries.Count()) {
lastError = dirHandle.Read(entries);
entryIndex = 0;
}
//each call to advance() gets the next entry from the entry list.
//from the final (or only) read call, KErrEof is returned together with a full buffer so we still need to go through the list
if ((lastError == KErrNone || lastError == KErrEof) && entryIndex < entries.Count()) {
Q_ASSERT(entryIndex >= 0);
const TEntry &entry(entries[entryIndex]);
fileEntry = QFileSystemEntry(nativePath + qt_TDesC2QString(entry.iName), QFileSystemEntry::FromNativePath());
metaData.fillFromTEntry(entry);
return true;
}
//TODO: error reporting, to allow user to distinguish empty directory from error condition.
return false;
}
示例9: isPackage
static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry)
{
if (!data.isDirectory())
return false;
QFileInfo info(entry.filePath());
QString suffix = info.suffix();
if (suffix.length() > 0) {
// First step: is the extension known ?
CFStringRef extensionRef = QCFString::toCFStringRef(suffix);
CFStringRef uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL);
if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle))
return true;
// Second step: check if an application knows the package type
CFStringRef path = QCFString::toCFStringRef(entry.filePath());
QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true);
UInt32 type, creator;
// Well created packages have the PkgInfo file
if (CFBundleGetPackageInfoInDirectory(url, &type, &creator))
return true;
// Find if an application other than Finder claims to know how to handle the package
QCFType<CFURLRef> application;
LSGetApplicationForURL(url,
kLSRolesEditor|kLSRolesViewer|kLSRolesViewer,
NULL,
&application);
if (application) {
QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application);
CFStringRef identifier = CFBundleGetIdentifier(bundle);
QString applicationId = QCFString::toQString(identifier);
if (applicationId != QLatin1String("com.apple.finder"))
return true;
}
}
// Third step: check if the directory has the package bit set
FSRef packageRef;
FSPathMakeRef((UInt8 *)entry.nativeFilePath().constData(), &packageRef, NULL);
FSCatalogInfo catalogInfo;
FSGetCatalogInfo(&packageRef,
kFSCatInfoFinderInfo,
&catalogInfo,
NULL,
NULL,
NULL);
FolderInfo *folderInfo = reinterpret_cast<FolderInfo *>(catalogInfo.finderInfo);
return folderInfo->finderFlags & kHasBundle;
}
示例10: fillMetaData
//static
bool QFileSystemEngine::fillMetaData(int fd, QFileSystemMetaData &data)
{
data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags;
data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags;
QT_STATBUF statBuffer;
if (QT_FSTAT(fd, &statBuffer) == 0) {
data.fillFromStatBuf(statBuffer);
return true;
}
return false;
}
示例11: fs
//static
bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
{
if (what & QFileSystemMetaData::SymbianTEntryFlags) {
RFs& fs(qt_s60GetRFs());
TInt err;
QFileSystemEntry absentry(absoluteName(entry));
if (entry.isEmpty()) {
err = KErrNotFound;
} else if (absentry.isRoot()) {
//Root directories don't have an entry, and Entry() returns KErrBadName.
//Therefore get information about the volume instead.
TInt drive;
err = RFs::CharToDrive(TChar(absentry.nativeFilePath().at(0).unicode()), drive);
if (!err) {
TVolumeInfo info;
err = fs.Volume(info, drive);
if (!err)
data.fillFromVolumeInfo(info);
}
} else {
TEntry ent;
err = fs.Entry(qt_QString2TPtrC(absentry.nativeFilePath()), ent);
if (!err)
data.fillFromTEntry(ent);
}
if (err) {
data.size_ = 0;
data.modificationTime_ = TTime(0);
data.entryFlags &= ~(QFileSystemMetaData::SymbianTEntryFlags);
}
//files in /sys/bin on any drive are executable, even though we don't normally have permission to check whether they exist or not
if(absentry.filePath().midRef(1,10).compare(QLatin1String(":/sys/bin/"), Qt::CaseInsensitive) == 0)
data.entryFlags |= QFileSystemMetaData::ExecutePermissions;
}
return data.hasFlags(what);
}
示例12: isPackage
static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry)
{
if (!data.isDirectory())
return false;
QFileInfo info(entry.filePath());
QString suffix = info.suffix();
if (suffix.length() > 0) {
// First step: is the extension known ?
QCFType<CFStringRef> extensionRef = QCFString::toCFStringRef(suffix);
QCFType<CFStringRef> uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL);
if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle))
return true;
// Second step: check if an application knows the package type
QCFType<CFStringRef> path = QCFString::toCFStringRef(entry.filePath());
QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true);
UInt32 type, creator;
// Well created packages have the PkgInfo file
if (CFBundleGetPackageInfoInDirectory(url, &type, &creator))
return true;
#ifdef Q_OS_OSX
// Find if an application other than Finder claims to know how to handle the package
QCFType<CFURLRef> application;
LSGetApplicationForURL(url,
kLSRolesEditor|kLSRolesViewer|kLSRolesViewer,
NULL,
&application);
if (application) {
QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application);
CFStringRef identifier = CFBundleGetIdentifier(bundle);
QString applicationId = QCFString::toQString(identifier);
if (applicationId != QLatin1String("com.apple.finder"))
return true;
}
#endif
}
// Third step: check if the directory has the package bit set
return hasResourcePropertyFlag(data, entry, kCFURLIsPackageKey);
}
示例13: Q_UNUSED
//static
QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
{
if (entry.isEmpty() || entry.isRoot())
return entry;
#if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && !defined(Q_OS_ANDROID) && !defined(Q_OS_HAIKU) && _POSIX_VERSION < 200809L
// realpath(X,0) is not supported
Q_UNUSED(data);
return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath()));
#else
char *ret = 0;
# if defined(Q_OS_DARWIN)
ret = (char*)malloc(PATH_MAX + 1);
if (ret && realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
const int savedErrno = errno; // errno is checked below, and free() might change it
free(ret);
errno = savedErrno;
ret = 0;
}
# elif defined(Q_OS_ANDROID)
// On some Android versions, realpath() will return a path even if it does not exist
// To work around this, we check existence in advance.
if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute))
fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
if (!data.exists()) {
ret = 0;
errno = ENOENT;
} else {
ret = (char*)malloc(PATH_MAX + 1);
if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
const int savedErrno = errno; // errno is checked below, and free() might change it
free(ret);
errno = savedErrno;
ret = 0;
}
}
# else
# if _POSIX_VERSION >= 200801L
ret = realpath(entry.nativeFilePath().constData(), (char*)0);
# else
ret = (char*)malloc(PATH_MAX + 1);
if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
const int savedErrno = errno; // errno is checked below, and free() might change it
free(ret);
errno = savedErrno;
ret = 0;
}
# endif
# endif
if (ret) {
data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
data.entryFlags |= QFileSystemMetaData::ExistsAttribute;
QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
free(ret);
return QFileSystemEntry(canonicalPath);
} else if (errno == ENOENT) { // file doesn't exist
data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
data.entryFlags &= ~(QFileSystemMetaData::ExistsAttribute);
return QFileSystemEntry();
}
return entry;
#endif
}
示例14: defined
//static
QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
{
#if defined(__GLIBC__) && !defined(PATH_MAX)
#define PATH_CHUNK_SIZE 256
char *s = 0;
int len = -1;
int size = PATH_CHUNK_SIZE;
while (1) {
s = (char *) ::realloc(s, size);
Q_CHECK_PTR(s);
len = ::readlink(link.nativeFilePath().constData(), s, size);
if (len < 0) {
::free(s);
break;
}
if (len < size) {
break;
}
size *= 2;
}
#else
char s[PATH_MAX+1];
int len = readlink(link.nativeFilePath().constData(), s, PATH_MAX);
#endif
if (len > 0) {
QString ret;
if (!data.hasFlags(QFileSystemMetaData::DirectoryType))
fillMetaData(link, data, QFileSystemMetaData::DirectoryType);
if (data.isDirectory() && s[0] != '/') {
QDir parent(link.filePath());
parent.cdUp();
ret = parent.path();
if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/')))
ret += QLatin1Char('/');
}
s[len] = '\0';
ret += QFile::decodeName(QByteArray(s));
#if defined(__GLIBC__) && !defined(PATH_MAX)
::free(s);
#endif
if (!ret.startsWith(QLatin1Char('/'))) {
if (link.filePath().startsWith(QLatin1Char('/'))) {
ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/')))
+ QLatin1Char('/'));
} else {
ret.prepend(QDir::currentPath() + QLatin1Char('/'));
}
}
ret = QDir::cleanPath(ret);
if (ret.size() > 1 && ret.endsWith(QLatin1Char('/')))
ret.chop(1);
return QFileSystemEntry(ret);
}
#if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
{
FSRef fref;
if (FSPathMakeRef((const UInt8 *)QFile::encodeName(QDir::cleanPath(link.filePath())).data(), &fref, 0) == noErr) {
// TODO get the meta data info from the QFileSystemMetaData object
Boolean isAlias, isFolder;
if (FSResolveAliasFile(&fref, true, &isFolder, &isAlias) == noErr && isAlias) {
AliasHandle alias;
if (FSNewAlias(0, &fref, &alias) == noErr && alias) {
QCFString cfstr;
if (FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr)
return QFileSystemEntry(QCFString::toQString(cfstr));
}
}
}
}
#endif
return QFileSystemEntry();
}
示例15: defined
//static
bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data,
QFileSystemMetaData::MetaDataFlags what)
{
#if defined(Q_OS_MACX)
if (what & QFileSystemMetaData::BundleType) {
if (!data.hasFlags(QFileSystemMetaData::DirectoryType))
what |= QFileSystemMetaData::DirectoryType;
}
if (what & QFileSystemMetaData::HiddenAttribute) {
// Mac OS >= 10.5: st_flags & UF_HIDDEN
what |= QFileSystemMetaData::PosixStatFlags;
}
#endif // defined(Q_OS_MACX)
if (what & QFileSystemMetaData::PosixStatFlags)
what |= QFileSystemMetaData::PosixStatFlags;
if (what & QFileSystemMetaData::ExistsAttribute) {
// FIXME: Would other queries being performed provide this bit?
what |= QFileSystemMetaData::PosixStatFlags;
}
data.entryFlags &= ~what;
const char * nativeFilePath;
int nativeFilePathLength;
{
const QByteArray &path = entry.nativeFilePath();
nativeFilePath = path.constData();
nativeFilePathLength = path.size();
Q_UNUSED(nativeFilePathLength);
}
bool entryExists = true; // innocent until proven otherwise
QT_STATBUF statBuffer;
bool statBufferValid = false;
if (what & QFileSystemMetaData::LinkType) {
if (QT_LSTAT(nativeFilePath, &statBuffer) == 0) {
if (S_ISLNK(statBuffer.st_mode)) {
data.entryFlags |= QFileSystemMetaData::LinkType;
} else {
statBufferValid = true;
data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags;
}
} else {
entryExists = false;
}
data.knownFlagsMask |= QFileSystemMetaData::LinkType;
}
if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) {
if (entryExists && !statBufferValid)
statBufferValid = (QT_STAT(nativeFilePath, &statBuffer) == 0);
if (statBufferValid)
data.fillFromStatBuf(statBuffer);
else {
entryExists = false;
data.creationTime_ = 0;
data.modificationTime_ = 0;
data.accessTime_ = 0;
data.size_ = 0;
data.userId_ = (uint) -2;
data.groupId_ = (uint) -2;
}
// reset the mask
data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags
| QFileSystemMetaData::ExistsAttribute;
}
#if defined(Q_OS_MACX)
if (what & QFileSystemMetaData::AliasType)
{
if (entryExists) {
FSRef fref;
if (FSPathMakeRef((const UInt8 *)nativeFilePath, &fref, NULL) == noErr) {
Boolean isAlias, isFolder;
if (FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr) {
if (isAlias)
data.entryFlags |= QFileSystemMetaData::AliasType;
}
}
}
data.knownFlagsMask |= QFileSystemMetaData::AliasType;
}
#endif
if (what & QFileSystemMetaData::UserPermissions) {
// calculate user permissions
if (entryExists) {
if (what & QFileSystemMetaData::UserReadPermission) {
if (QT_ACCESS(nativeFilePath, R_OK) == 0)
data.entryFlags |= QFileSystemMetaData::UserReadPermission;
}
if (what & QFileSystemMetaData::UserWritePermission) {
//.........这里部分代码省略.........