Пример #1
0
 KFileItemPrivate(const KIO::UDSEntry &entry,
                  mode_t mode, mode_t permissions,
                  const QUrl &itemOrDirUrl,
                  bool urlIsDirectory,
                  bool delayedMimeTypes)
     : m_entry(entry),
       m_url(itemOrDirUrl),
       m_strName(),
       m_strText(),
       m_iconName(),
       m_strLowerCaseName(),
       m_mimeType(),
       m_fileMode(mode),
       m_permissions(permissions),
       m_bLink(false),
       m_bIsLocalUrl(itemOrDirUrl.isLocalFile()),
       m_bMimeTypeKnown(false),
       m_delayedMimeTypes(delayedMimeTypes),
       m_useIconNameCache(false),
       m_hidden(Auto),
       m_slow(SlowUnknown)
 {
     if (entry.count() != 0) {
         readUDSEntry(urlIsDirectory);
     } else {
         Q_ASSERT(!urlIsDirectory);
         m_strName = itemOrDirUrl.fileName();
         m_strText = KIO::decodeFileName(m_strName);
     }
     init();
 }
Пример #2
0
void KFileItemPrivate::init()
{
    m_access.clear();
    //  metaInfo = KFileMetaInfo();

    // stat() local files if needed
    // TODO: delay this until requested
    if (m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown || m_entry.count() == 0) {
        if (m_url.isLocalFile()) {
            /* directories may not have a slash at the end if
             * we want to stat() them; it requires that we
             * change into it .. which may not be allowed
             * stat("/is/unaccessible")  -> rwx------
             * stat("/is/unaccessible/") -> EPERM            H.Z.
             * This is the reason for the StripTrailingSlash
             */
            QT_STATBUF buf;
            const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile();
            const QByteArray pathBA = QFile::encodeName(path);
            if (QT_LSTAT(pathBA.constData(), &buf) == 0) {
                m_entry.insert(KIO::UDSEntry::UDS_DEVICE_ID,           buf.st_dev);
                m_entry.insert(KIO::UDSEntry::UDS_INODE,               buf.st_ino);

                mode_t mode = buf.st_mode;
                if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) {
                    m_bLink = true;
                    if (QT_STAT(pathBA, &buf) == 0) {
                        mode = buf.st_mode;
                    } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in ioslaves/file/file.cpp)
                        mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO;
                    }
                }
                m_entry.insert(KIO::UDSEntry::UDS_SIZE,      buf.st_size);
                m_entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, buf.st_mode & QT_STAT_MASK); // extract file type
                m_entry.insert(KIO::UDSEntry::UDS_ACCESS,    buf.st_mode & 07777); // extract permissions
                m_entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,   buf.st_mtime); // TODO: we could use msecs too...
                m_entry.insert(KIO::UDSEntry::UDS_ACCESS_TIME,         buf.st_atime);
#ifndef Q_OS_WIN
                m_entry.insert(KIO::UDSEntry::UDS_USER,                KUser(buf.st_uid).loginName());
                m_entry.insert(KIO::UDSEntry::UDS_GROUP,               KUserGroup(buf.st_gid).name());
#endif

                // TODO: these can be removed, we can use UDS_FILE_TYPE and UDS_ACCESS everywhere
                if (m_fileMode == KFileItem::Unknown) {
                    m_fileMode = mode & QT_STAT_MASK; // extract file type
                }
                if (m_permissions == KFileItem::Unknown) {
                    m_permissions = mode & 07777; // extract permissions
                }
            }
        }
    }
}