mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-25 03:12:56 +00:00
win and mac leftovers removal from QFileInfo and friends
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
ebe5f97386
commit
da72643035
9 changed files with 21 additions and 225 deletions
|
@ -300,7 +300,6 @@ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName)
|
|||
the file system (i.e. not a file or directory).
|
||||
\value FileType The file is a regular file to the file system
|
||||
(i.e. not a link or directory)
|
||||
\value BundleType The file is a Mac OS X bundle implies DirectoryType
|
||||
\value DirectoryType The file is a directory in the file system
|
||||
(i.e. not a link or file).
|
||||
|
||||
|
|
|
@ -72,7 +72,6 @@ public:
|
|||
LinkType = 0x10000,
|
||||
FileType = 0x20000,
|
||||
DirectoryType = 0x40000,
|
||||
BundleType = 0x80000,
|
||||
|
||||
//flags
|
||||
HiddenFlag = 0x0100000,
|
||||
|
|
|
@ -123,8 +123,7 @@ QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const
|
|||
uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const
|
||||
{
|
||||
Q_ASSERT(fileEngine); // should never be called when using the native FS
|
||||
// We split the testing into tests for for LinkType, BundleType, PermsMask
|
||||
// and the rest.
|
||||
// We split the testing into tests for for LinkType, PermsMask and the rest.
|
||||
// Tests for file permissions on Windows can be slow, expecially on network
|
||||
// paths and NTFS drives.
|
||||
// In order to determine if a file is a symlink or not, we have to lstat().
|
||||
|
@ -140,7 +139,6 @@ uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) cons
|
|||
req |= QAbstractFileEngine::FlagsMask;
|
||||
req |= QAbstractFileEngine::TypesMask;
|
||||
req &= (~QAbstractFileEngine::LinkType);
|
||||
req &= (~QAbstractFileEngine::BundleType);
|
||||
|
||||
cachedFlags |= CachedFileFlags;
|
||||
}
|
||||
|
@ -151,13 +149,6 @@ uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) cons
|
|||
cachedFlags |= CachedLinkTypeFlag;
|
||||
}
|
||||
}
|
||||
|
||||
if (request & QAbstractFileEngine::BundleType) {
|
||||
if (!getCachedFlag(CachedBundleTypeFlag)) {
|
||||
req |= QAbstractFileEngine::BundleType;
|
||||
cachedFlags |= CachedBundleTypeFlag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (request & QAbstractFileEngine::PermsMask) {
|
||||
|
@ -905,7 +896,7 @@ bool QFileInfo::isHidden() const
|
|||
link to a file. Returns false if the
|
||||
object points to something which isn't a file, such as a directory.
|
||||
|
||||
\sa isDir(), isSymLink(), isBundle()
|
||||
\sa isDir(), isSymLink()
|
||||
*/
|
||||
bool QFileInfo::isFile() const
|
||||
{
|
||||
|
@ -924,7 +915,7 @@ bool QFileInfo::isFile() const
|
|||
Returns true if this object points to a directory or to a symbolic
|
||||
link to a directory; otherwise returns false.
|
||||
|
||||
\sa isFile(), isSymLink(), isBundle()
|
||||
\sa isFile(), isSymLink()
|
||||
*/
|
||||
bool QFileInfo::isDir() const
|
||||
{
|
||||
|
@ -939,27 +930,6 @@ bool QFileInfo::isDir() const
|
|||
return d->getFileFlags(QAbstractFileEngine::DirectoryType);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\since 4.3
|
||||
Returns true if this object points to a bundle or to a symbolic
|
||||
link to a bundle on Mac OS X; otherwise returns false.
|
||||
|
||||
\sa isDir(), isSymLink(), isFile()
|
||||
*/
|
||||
bool QFileInfo::isBundle() const
|
||||
{
|
||||
Q_D(const QFileInfo);
|
||||
if (d->isDefaultConstructed)
|
||||
return false;
|
||||
if (d->fileEngine == 0) {
|
||||
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::BundleType))
|
||||
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::BundleType);
|
||||
return d->metaData.isBundle();
|
||||
}
|
||||
return d->getFileFlags(QAbstractFileEngine::BundleType);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns true if this object points to a symbolic link (or to a
|
||||
shortcut on Windows); otherwise returns false.
|
||||
|
@ -983,9 +953,9 @@ bool QFileInfo::isSymLink() const
|
|||
if (d->isDefaultConstructed)
|
||||
return false;
|
||||
if (d->fileEngine == 0) {
|
||||
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::LegacyLinkType))
|
||||
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::LegacyLinkType);
|
||||
return d->metaData.isLegacyLink();
|
||||
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::LinkType))
|
||||
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::LinkType);
|
||||
return d->metaData.isLink();
|
||||
}
|
||||
return d->getFileFlags(QAbstractFileEngine::LinkType);
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@ public:
|
|||
bool isDir() const;
|
||||
bool isSymLink() const;
|
||||
bool isRoot() const;
|
||||
bool isBundle() const;
|
||||
|
||||
QString readLink() const;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
|
|||
class QFileInfoPrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
enum { CachedFileFlags=0x01, CachedLinkTypeFlag=0x02, CachedBundleTypeFlag=0x04,
|
||||
enum { CachedFileFlags=0x01, CachedLinkTypeFlag=0x02,
|
||||
CachedMTime=0x10, CachedCTime=0x20, CachedATime=0x40,
|
||||
CachedSize =0x08, CachedPerms=0x80 };
|
||||
|
||||
|
|
|
@ -345,8 +345,6 @@ void QFileSystemMetaData::fillFromDirEnt(const QT_DIRENT &entry)
|
|||
knownFlagsMask = QFileSystemMetaData::LinkType
|
||||
| QFileSystemMetaData::FileType
|
||||
| QFileSystemMetaData::DirectoryType
|
||||
| QFileSystemMetaData::BundleType
|
||||
| QFileSystemMetaData::AliasType
|
||||
| QFileSystemMetaData::SequentialType
|
||||
| QFileSystemMetaData::ExistsAttribute;
|
||||
|
||||
|
@ -364,7 +362,6 @@ void QFileSystemMetaData::fillFromDirEnt(const QT_DIRENT &entry)
|
|||
knownFlagsMask = QFileSystemMetaData::LinkType
|
||||
| QFileSystemMetaData::FileType
|
||||
| QFileSystemMetaData::DirectoryType
|
||||
| QFileSystemMetaData::BundleType
|
||||
| QFileSystemMetaData::SequentialType
|
||||
| QFileSystemMetaData::ExistsAttribute;
|
||||
|
||||
|
|
|
@ -209,23 +209,6 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link,
|
|||
ret.chop(1);
|
||||
return QFileSystemEntry(ret);
|
||||
}
|
||||
#if 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();
|
||||
}
|
||||
|
||||
|
@ -235,40 +218,15 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
|
|||
if (entry.isEmpty() || entry.isRoot())
|
||||
return entry;
|
||||
|
||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && _POSIX_VERSION < 200809L
|
||||
#if _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_MAC) && !defined(Q_OS_IOS)
|
||||
// When using -mmacosx-version-min=10.4, we get the legacy realpath implementation,
|
||||
// which does not work properly with the realpath(X,0) form. See QTBUG-28282.
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
// on 10.5 we can use FSRef to resolve the file path.
|
||||
QString path = QDir::cleanPath(entry.filePath());
|
||||
FSRef fsref;
|
||||
if (FSPathMakeRef((const UInt8 *)path.toUtf8().data(), &fsref, 0) == noErr) {
|
||||
CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref);
|
||||
CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle);
|
||||
QString ret = QCFString::toQString(canonicalPath);
|
||||
CFRelease(canonicalPath);
|
||||
CFRelease(urlref);
|
||||
return QFileSystemEntry(ret);
|
||||
}
|
||||
}
|
||||
# else
|
||||
# if _POSIX_VERSION >= 200801L
|
||||
#if _POSIX_VERSION >= 200801L
|
||||
ret = realpath(entry.nativeFilePath().constData(), (char*)0);
|
||||
# else
|
||||
#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
|
||||
|
@ -276,8 +234,7 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
|
|||
errno = savedErrno;
|
||||
ret = 0;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
if (ret) {
|
||||
data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
|
||||
data.entryFlags |= QFileSystemMetaData::ExistsAttribute;
|
||||
|
@ -450,23 +407,6 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
|
|||
| QFileSystemMetaData::ExistsAttribute;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
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
|
||||
|
||||
|
@ -496,14 +436,6 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
|
|||
data.knownFlagsMask |= QFileSystemMetaData::HiddenAttribute;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
if (what & QFileSystemMetaData::BundleType) {
|
||||
if (entryExists && isPackage(data, entry))
|
||||
data.entryFlags |= QFileSystemMetaData::BundleType;
|
||||
data.knownFlagsMask |= QFileSystemMetaData::BundleType;
|
||||
}
|
||||
#endif
|
||||
|
||||
return data.hasFlags(what);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,23 +91,9 @@ public:
|
|||
LinkType = 0x00010000,
|
||||
FileType = 0x00020000,
|
||||
DirectoryType = 0x00040000,
|
||||
#if defined(Q_OS_MAC)
|
||||
BundleType = 0x00080000,
|
||||
AliasType = 0x08000000,
|
||||
#else
|
||||
BundleType = 0x0,
|
||||
AliasType = 0x0,
|
||||
#endif
|
||||
#if defined(Q_OS_WIN)
|
||||
WinLnkType = 0x08000000, // Note: Uses the same position for AliasType on Mac
|
||||
#else
|
||||
WinLnkType = 0x0,
|
||||
#endif
|
||||
SequentialType = 0x00800000, // Note: overlaps with QAbstractFileEngine::RootFlag
|
||||
|
||||
LegacyLinkType = LinkType | AliasType | WinLnkType,
|
||||
|
||||
Type = LinkType | FileType | DirectoryType | BundleType | SequentialType | AliasType,
|
||||
Type = LinkType | FileType | DirectoryType | SequentialType,
|
||||
|
||||
// Attributes
|
||||
HiddenAttribute = 0x00100000,
|
||||
|
@ -169,9 +155,6 @@ public:
|
|||
bool isLink() const { return (entryFlags & LinkType); }
|
||||
bool isFile() const { return (entryFlags & FileType); }
|
||||
bool isDirectory() const { return (entryFlags & DirectoryType); }
|
||||
bool isBundle() const;
|
||||
bool isAlias() const;
|
||||
bool isLegacyLink() const { return (entryFlags & LegacyLinkType); }
|
||||
bool isSequential() const { return (entryFlags & SequentialType); }
|
||||
bool isHidden() const { return (entryFlags & HiddenAttribute); }
|
||||
|
||||
|
@ -210,15 +193,7 @@ private:
|
|||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemMetaData::MetaDataFlags)
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
inline bool QFileSystemMetaData::isBundle() const { return (entryFlags & BundleType); }
|
||||
inline bool QFileSystemMetaData::isAlias() const { return (entryFlags & AliasType); }
|
||||
#else
|
||||
inline bool QFileSystemMetaData::isBundle() const { return false; }
|
||||
inline bool QFileSystemMetaData::isAlias() const { return false; }
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_UNIX) || defined (Q_OS_WIN)
|
||||
#if defined(Q_OS_UNIX)
|
||||
inline QDateTime QFileSystemMetaData::fileTime(QAbstractFileEngine::FileTime time) const
|
||||
{
|
||||
switch (time) {
|
||||
|
@ -253,73 +228,6 @@ inline uint QFileSystemMetaData::ownerId(QAbstractFileEngine::FileOwner owner) c
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
inline uint QFileSystemMetaData::userId() const { return (uint) -2; }
|
||||
inline uint QFileSystemMetaData::groupId() const { return (uint) -2; }
|
||||
inline uint QFileSystemMetaData::ownerId(QAbstractFileEngine::FileOwner owner) const
|
||||
{
|
||||
if (owner == QAbstractFileEngine::OwnerUser)
|
||||
return userId();
|
||||
else
|
||||
return groupId();
|
||||
}
|
||||
|
||||
inline void QFileSystemMetaData::fillFromFileAttribute(DWORD fileAttribute,bool isDriveRoot)
|
||||
{
|
||||
fileAttribute_ = fileAttribute;
|
||||
// Ignore the hidden attribute for drives.
|
||||
if (!isDriveRoot && (fileAttribute_ & FILE_ATTRIBUTE_HIDDEN))
|
||||
entryFlags |= HiddenAttribute;
|
||||
entryFlags |= ((fileAttribute & FILE_ATTRIBUTE_DIRECTORY) ? DirectoryType: FileType);
|
||||
entryFlags |= ExistsAttribute;
|
||||
knownFlagsMask |= FileType | DirectoryType | HiddenAttribute | ExistsAttribute;
|
||||
}
|
||||
|
||||
inline void QFileSystemMetaData::fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType, bool isDriveRoot)
|
||||
{
|
||||
fillFromFileAttribute(findData.dwFileAttributes, isDriveRoot);
|
||||
creationTime_ = findData.ftCreationTime;
|
||||
lastAccessTime_ = findData.ftLastAccessTime;
|
||||
lastWriteTime_ = findData.ftLastWriteTime;
|
||||
if (fileAttribute_ & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
size_ = 0;
|
||||
} else {
|
||||
size_ = findData.nFileSizeHigh;
|
||||
size_ <<= 32;
|
||||
size_ += findData.nFileSizeLow;
|
||||
}
|
||||
knownFlagsMask |= Times | SizeAttribute;
|
||||
if (setLinkType) {
|
||||
knownFlagsMask |= LinkType;
|
||||
entryFlags &= ~LinkType;
|
||||
#if !defined(Q_OS_WINCE)
|
||||
if ((fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT)
|
||||
&& findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
|
||||
entryFlags |= LinkType;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
inline void QFileSystemMetaData::fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo)
|
||||
{
|
||||
fillFromFileAttribute(fileInfo.dwFileAttributes);
|
||||
creationTime_ = fileInfo.ftCreationTime;
|
||||
lastAccessTime_ = fileInfo.ftLastAccessTime;
|
||||
lastWriteTime_ = fileInfo.ftLastWriteTime;
|
||||
if (fileAttribute_ & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
size_ = 0;
|
||||
} else {
|
||||
size_ = fileInfo.nFileSizeHigh;
|
||||
size_ <<= 32;
|
||||
size_ += fileInfo.nFileSizeLow;
|
||||
}
|
||||
knownFlagsMask |= Times | SizeAttribute;
|
||||
}
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // include guard
|
||||
|
|
|
@ -514,11 +514,9 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const
|
|||
& QFileSystemMetaData::Permissions;
|
||||
|
||||
if (type & TypesMask)
|
||||
queryFlags |= QFileSystemMetaData::AliasType
|
||||
| QFileSystemMetaData::LinkType
|
||||
queryFlags |= QFileSystemMetaData::LinkType
|
||||
| QFileSystemMetaData::FileType
|
||||
| QFileSystemMetaData::DirectoryType
|
||||
| QFileSystemMetaData::BundleType;
|
||||
| QFileSystemMetaData::DirectoryType;
|
||||
|
||||
if (type & FlagsMask)
|
||||
queryFlags |= QFileSystemMetaData::HiddenAttribute
|
||||
|
@ -536,19 +534,13 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const
|
|||
ret |= FileFlags(uint(d->metaData.permissions()));
|
||||
|
||||
if (type & TypesMask) {
|
||||
if (d->metaData.isAlias()) {
|
||||
if ((type & LinkType) && d->metaData.isLink())
|
||||
ret |= LinkType;
|
||||
} else {
|
||||
if ((type & LinkType) && d->metaData.isLink())
|
||||
ret |= LinkType;
|
||||
if (exists) {
|
||||
if (d->metaData.isFile()) {
|
||||
ret |= FileType;
|
||||
} else if (d->metaData.isDirectory()) {
|
||||
ret |= DirectoryType;
|
||||
if ((type & BundleType) && d->metaData.isBundle())
|
||||
ret |= BundleType;
|
||||
}
|
||||
if (exists) {
|
||||
if (d->metaData.isFile()) {
|
||||
ret |= FileType;
|
||||
} else if (d->metaData.isDirectory()) {
|
||||
ret |= DirectoryType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue