diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2010-09-07 10:50:51 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2010-09-07 15:41:32 (GMT) |
commit | a6611da5a67f2689586fd9367405dec2429f9cde (patch) | |
tree | 67e8b51324bec0ae480a7a4da2c0bf1a3934932c | |
parent | 309f0d3d1f4bcc42249e738bae544750fe8cdb6a (diff) | |
download | Qt-a6611da5a67f2689586fd9367405dec2429f9cde.zip Qt-a6611da5a67f2689586fd9367405dec2429f9cde.tar.gz Qt-a6611da5a67f2689586fd9367405dec2429f9cde.tar.bz2 |
Symbian OS implementation for QFileSystemMetaData
There are three possible sources for metadata:
RFs::Entry() - for files or directories in the filesystem (except roots)
RFs::Volume() - for mounted drives (used for root directory)
::fstat() - for Open C file handles adopted via QFile::open(int, OpenMode)
As a result of the ::fstat requirement, the code dealing with stat buffers
is moved from qfilesystemengine_unix.cpp to the common qfilesystemengine.cpp
Reviewed-By: joao
-rw-r--r-- | src/corelib/io/qfilesystemengine.cpp | 72 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_symbian.cpp | 74 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 63 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemmetadata_p.h | 46 |
4 files changed, 187 insertions, 68 deletions
diff --git a/src/corelib/io/qfilesystemengine.cpp b/src/corelib/io/qfilesystemengine.cpp index 8f5b98a..0563a15 100644 --- a/src/corelib/io/qfilesystemengine.cpp +++ b/src/corelib/io/qfilesystemengine.cpp @@ -213,4 +213,76 @@ QAbstractFileEngine *QFileSystemEngine::resolveEntryAndCreateLegacyEngine( return engine; } +//these unix functions are in this file, because they are shared by symbian port +//for open C file handles. +#ifdef Q_OS_UNIX +//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; +} + +void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer) +{ + // Permissions + if (statBuffer.st_mode & S_IRUSR) + entryFlags |= QFileSystemMetaData::OwnerReadPermission; + if (statBuffer.st_mode & S_IWUSR) + entryFlags |= QFileSystemMetaData::OwnerWritePermission; + if (statBuffer.st_mode & S_IXUSR) + entryFlags |= QFileSystemMetaData::OwnerExecutePermission; + + if (statBuffer.st_mode & S_IRGRP) + entryFlags |= QFileSystemMetaData::GroupReadPermission; + if (statBuffer.st_mode & S_IWGRP) + entryFlags |= QFileSystemMetaData::GroupWritePermission; + if (statBuffer.st_mode & S_IXGRP) + entryFlags |= QFileSystemMetaData::GroupExecutePermission; + + if (statBuffer.st_mode & S_IROTH) + entryFlags |= QFileSystemMetaData::OtherReadPermission; + if (statBuffer.st_mode & S_IWOTH) + entryFlags |= QFileSystemMetaData::OtherWritePermission; + if (statBuffer.st_mode & S_IXOTH) + entryFlags |= QFileSystemMetaData::OtherExecutePermission; + + // Type + if ((statBuffer.st_mode & S_IFMT) == S_IFREG) + entryFlags |= QFileSystemMetaData::FileType; + else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR) + entryFlags |= QFileSystemMetaData::DirectoryType; + else + entryFlags |= QFileSystemMetaData::SequentialType; + + // Attributes + entryFlags |= QFileSystemMetaData::ExistsAttribute; + size_ = statBuffer.st_size; +#if !defined(QWS) && defined(Q_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + if (statBuffer.st_flags & UF_HIDDEN) { + entryFlags |= QFileSystemMetaData::HiddenAttribute; + knownFlagsMask |= QFileSystemMetaData::HiddenAttribute; + } +#endif + + // Times +#ifdef Q_OS_SYMBIAN + modificationTime_ = qt_symbian_time_t_To_TTime(statBuffer.st_mtime); +#else + creationTime_ = statBuffer.st_ctime ? statBuffer.st_ctime : statBuffer.st_mtime; + modificationTime_ = statBuffer.st_mtime; + accessTime_ = statBuffer.st_atime; +#endif +} + +#endif + QT_END_NAMESPACE diff --git a/src/corelib/io/qfilesystemengine_symbian.cpp b/src/corelib/io/qfilesystemengine_symbian.cpp index 2798bdf..19f149a 100644 --- a/src/corelib/io/qfilesystemengine_symbian.cpp +++ b/src/corelib/io/qfilesystemengine_symbian.cpp @@ -108,13 +108,76 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) //static QString QFileSystemEngine::bundleName(const QFileSystemEntry &entry) { - return QString(); // TODO implement; + Q_UNUSED(entry); + return QString(); +} + +void QFileSystemMetaData::fillFromTEntry(const TEntry& entry) +{ + //Symbian doesn't have unix type file permissions + entryFlags |= QFileSystemMetaData::Permissions; + if(entry.IsReadOnly()) { + entryFlags &= ~(QFileSystemMetaData::WritePermissions); + } + //set the type + if(entry.IsDir()) + entryFlags |= QFileSystemMetaData::DirectoryType; + else + entryFlags |= QFileSystemMetaData::FileType; + + //set the attributes + entryFlags |= QFileSystemMetaData::ExistsAttribute; + if(entry.IsHidden()) + entryFlags |= QFileSystemMetaData::HiddenAttribute; + +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API + size_ = entry.FileSize(); +#else + size_ = (TUint)(entry.iSize); +#endif + + modificationTime_ = entry.iModified; +} + +void QFileSystemMetaData::fillFromVolumeInfo(const TVolumeInfo& info) +{ + entryFlags |= QFileSystemMetaData::ExistsAttribute; + entryFlags |= QFileSystemMetaData::Permissions; + if(info.iDrive.iDriveAtt & KDriveAttRom) { + entryFlags &= ~(QFileSystemMetaData::WritePermissions); + } + entryFlags |= QFileSystemMetaData::DirectoryType; + size_ = info.iSize; + modificationTime_ = qt_symbian_time_t_To_TTime(0); } //static bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what) { - return false; // TODO implement; + if (what & QFileSystemMetaData::SymbianTEntryFlags) { + RFs& fs(qt_s60GetRFs()); + TInt err; + data.entryFlags &= ~(QFileSystemMetaData::SymbianTEntryFlags); + if (entry.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(entry.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(absoluteName(entry).nativeFilePath()), ent); + if (!err) + data.fillFromTEntry(ent); + } + data.knownFlagsMask |= QFileSystemMetaData::SymbianTEntryFlags; + } + return data.hasFlags(what); } //static @@ -207,7 +270,12 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per else setmask = KEntryAttReadOnly; TInt err = fs.SetAtt(qt_QString2TPtrC(targetpath), setmask, clearmask); - return err != KErrNone; // TODO error reporting, metadata update; + if (data && !err) { + data->entryFlags &= ~QFileSystemMetaData::Permissions; + data->entryFlags |= QFileSystemMetaData::MetaDataFlag(uint(permissions)); + data->knownFlagsMask |= QFileSystemMetaData::Permissions; + } + return err != KErrNone; // TODO error reporting } QT_END_NAMESPACE diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 755298d..f26a8c0 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -105,54 +105,6 @@ static inline bool _q_isMacHidden(const char *nativePath) } #endif -void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer) -{ - // Permissions - if (statBuffer.st_mode & S_IRUSR) - entryFlags |= QFileSystemMetaData::OwnerReadPermission; - if (statBuffer.st_mode & S_IWUSR) - entryFlags |= QFileSystemMetaData::OwnerWritePermission; - if (statBuffer.st_mode & S_IXUSR) - entryFlags |= QFileSystemMetaData::OwnerExecutePermission; - - if (statBuffer.st_mode & S_IRGRP) - entryFlags |= QFileSystemMetaData::GroupReadPermission; - if (statBuffer.st_mode & S_IWGRP) - entryFlags |= QFileSystemMetaData::GroupWritePermission; - if (statBuffer.st_mode & S_IXGRP) - entryFlags |= QFileSystemMetaData::GroupExecutePermission; - - if (statBuffer.st_mode & S_IROTH) - entryFlags |= QFileSystemMetaData::OtherReadPermission; - if (statBuffer.st_mode & S_IWOTH) - entryFlags |= QFileSystemMetaData::OtherWritePermission; - if (statBuffer.st_mode & S_IXOTH) - entryFlags |= QFileSystemMetaData::OtherExecutePermission; - - // Type - if ((statBuffer.st_mode & S_IFMT) == S_IFREG) - entryFlags |= QFileSystemMetaData::FileType; - else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR) - entryFlags |= QFileSystemMetaData::DirectoryType; - else - entryFlags |= QFileSystemMetaData::SequentialType; - - // Attributes - entryFlags |= QFileSystemMetaData::ExistsAttribute; - size_ = statBuffer.st_size; -#if !defined(QWS) && defined(Q_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 - if (statBuffer.st_flags & UF_HIDDEN) { - entryFlags |= QFileSystemMetaData::HiddenAttribute; - knownFlagsMask |= QFileSystemMetaData::HiddenAttribute; - } -#endif - - // Times - creationTime_ = statBuffer.st_ctime ? statBuffer.st_ctime : statBuffer.st_mtime; - modificationTime_ = statBuffer.st_mtime; - accessTime_ = statBuffer.st_atime; -} - bool QFileSystemEngine::isCaseSensitive() { #if defined(Q_OS_SYMBIAN) @@ -329,21 +281,6 @@ QString QFileSystemEngine::bundleName(const QFileSystemEntry &entry) } //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; -} - -//static bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what) { diff --git a/src/corelib/io/qfilesystemmetadata_p.h b/src/corelib/io/qfilesystemmetadata_p.h index 5914eb3..f140319 100644 --- a/src/corelib/io/qfilesystemmetadata_p.h +++ b/src/corelib/io/qfilesystemmetadata_p.h @@ -60,6 +60,9 @@ // Platform-specific includes #if defined(Q_OS_WIN) +#elif defined(Q_OS_SYMBIAN) +#include <f32file.h> +#include "qdatetime_p.h" #else #endif @@ -86,10 +89,18 @@ struct QFileSystemMetaData UserPermissions = UserReadPermission | UserWritePermission | UserExecutePermission, OwnerPermissions = OwnerReadPermission | OwnerWritePermission | OwnerExecutePermission, + ReadPermissions = OtherReadPermission | GroupReadPermission | UserReadPermission | OwnerReadPermission, + WritePermissions = OtherWritePermission | GroupWritePermission | UserWritePermission | OwnerWritePermission, + ExecutePermissions = OtherExecutePermission | GroupExecutePermission | UserExecutePermission | OwnerExecutePermission, + Permissions = OtherPermissions | GroupPermissions | UserPermissions | OwnerPermissions, // Type +#ifdef Q_OS_SYMBIAN + LinkType = 0, +#else LinkType = 0x00010000, +#endif FileType = 0x00020000, DirectoryType = 0x00040000, #if !defined(QWS) && defined(Q_OS_MAC) @@ -137,6 +148,13 @@ struct QFileSystemMetaData | QFileSystemMetaData::Times | QFileSystemMetaData::OwnerIds, + SymbianTEntryFlags = QFileSystemMetaData::Permissions + | QFileSystemMetaData::FileType + | QFileSystemMetaData::DirectoryType + | QFileSystemMetaData::SequentialType + | QFileSystemMetaData::Attributes + | QFileSystemMetaData::Times, + AllMetaDataFlags = 0xFFFFFFFF }; @@ -181,7 +199,7 @@ struct QFileSystemMetaData QFile::Permissions permissions() const { return QFile::Permissions(Permissions & entryFlags); } -#if defined(Q_OS_UNIX) +#if defined(Q_OS_UNIX) && !defined (Q_OS_SYMBIAN) QDateTime creationTime() const { return QDateTime::fromTime_t(creationTime_); } QDateTime modificationTime() const { return QDateTime::fromTime_t(modificationTime_); } QDateTime accessTime() const { return QDateTime::fromTime_t(accessTime_); } @@ -213,9 +231,31 @@ struct QFileSystemMetaData else return groupId(); } - +#endif +#ifdef Q_OS_UNIX void fillFromStatBuf(const QT_STATBUF &statBuffer); #endif +#ifdef Q_OS_SYMBIAN + QDateTime creationTime() const { return modificationTime(); } + QDateTime modificationTime() const { return qt_symbian_TTime_To_QDateTime(modificationTime_); } + QDateTime accessTime() const { return modificationTime(); } + + QDateTime fileTime(QAbstractFileEngine::FileTime time) const + { + Q_UNUSED(time); + return modificationTime(); + } + uint userId() const { return (uint) -2; } + uint groupId() const { return (uint) -2; } + uint ownerId(QAbstractFileEngine::FileOwner owner) const + { + Q_UNUSED(owner); + return (uint) -2; + } + + void fillFromTEntry(const TEntry& entry); + void fillFromVolumeInfo(const TVolumeInfo& info); +#endif private: friend class QFileSystemEngine; @@ -227,6 +267,8 @@ private: // Platform-specific data goes here: #if defined(Q_OS_WIN) +#elif defined(Q_OS_SYMBIAN) + TTime modificationTime_; #else time_t creationTime_; time_t modificationTime_; |