File indexing completed on 2024-05-12 11:45:22
0001 /* 0002 SPDX-FileCopyrightText: 2005 David Faure <faure@kde.org> 0003 SPDX-FileCopyrightText: 2007 Thiago Macieira <thiago@kde.org> 0004 SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <bruns@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef BALOO_KIO_COMMON_UDSTOOLS_H_ 0010 #define BALOO_KIO_COMMON_UDSTOOLS_H_ 0011 0012 #include "usergroupcache.h" 0013 #include "idutils.h" 0014 0015 namespace Baloo { 0016 0017 class UdsFactory 0018 { 0019 public: 0020 KIO::UDSEntry createUdsEntry(const QString& filePath) const; 0021 0022 private: 0023 UserGroupCache m_userGroupCache; 0024 }; 0025 0026 inline KIO::UDSEntry UdsFactory::createUdsEntry(const QString& filePath) const 0027 { 0028 KIO::UDSEntry uds; 0029 0030 QT_STATBUF statBuf; 0031 const QByteArray ba = QFile::encodeName(filePath); 0032 if (filePathToStat(ba, statBuf) != 0) { 0033 return uds; 0034 } 0035 0036 uds.reserve(12); 0037 uds.fastInsert(KIO::UDSEntry::UDS_DEVICE_ID, statBuf.st_dev); 0038 uds.fastInsert(KIO::UDSEntry::UDS_INODE, statBuf.st_ino); 0039 0040 mode_t type = statBuf.st_mode & S_IFMT; 0041 mode_t access = statBuf.st_mode & 07777; 0042 0043 uds.fastInsert(KIO::UDSEntry::UDS_SIZE, statBuf.st_size); 0044 uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, type); 0045 uds.fastInsert(KIO::UDSEntry::UDS_ACCESS, access); 0046 uds.fastInsert(KIO::UDSEntry::UDS_MODIFICATION_TIME, statBuf.st_mtime); 0047 uds.fastInsert(KIO::UDSEntry::UDS_ACCESS_TIME, statBuf.st_atime); 0048 #ifndef Q_OS_WIN 0049 uds.fastInsert(KIO::UDSEntry::UDS_USER, m_userGroupCache.getUserName(KUserId(statBuf.st_uid))); 0050 uds.fastInsert(KIO::UDSEntry::UDS_GROUP, m_userGroupCache.getGroupName(KGroupId(statBuf.st_gid))); 0051 #else 0052 #pragma message("TODO: st_uid and st_gid are always zero, use GetSecurityInfo to find the owner") 0053 #endif 0054 0055 QUrl url = QUrl::fromLocalFile(filePath); 0056 uds.fastInsert(KIO::UDSEntry::UDS_NAME, url.fileName()); 0057 uds.fastInsert(KIO::UDSEntry::UDS_URL, url.url()); 0058 uds.fastInsert(KIO::UDSEntry::UDS_LOCAL_PATH, filePath); 0059 0060 return uds; 0061 } 0062 0063 } 0064 #endif