Baloo

udstools.h
1 /*
2  SPDX-FileCopyrightText: 2005 David Faure <[email protected]>
3  SPDX-FileCopyrightText: 2007 Thiago Macieira <[email protected]>
4  SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef BALOO_KIO_COMMON_UDSTOOLS_H_
10 #define BALOO_KIO_COMMON_UDSTOOLS_H_
11 
12 #include "usergroupcache.h"
13 #include "idutils.h"
14 
15 namespace Baloo {
16 
17 class UdsFactory
18 {
19 public:
20  KIO::UDSEntry createUdsEntry(const QString& filePath) const;
21 
22 private:
23  UserGroupCache m_userGroupCache;
24 };
25 
26 inline KIO::UDSEntry UdsFactory::createUdsEntry(const QString& filePath) const
27 {
28  KIO::UDSEntry uds;
29 
30  QT_STATBUF statBuf;
31  const QByteArray ba = QFile::encodeName(filePath);
32  if (filePathToStat(ba, statBuf) != 0) {
33  return uds;
34  }
35 
36  uds.reserve(12);
37  uds.fastInsert(KIO::UDSEntry::UDS_DEVICE_ID, statBuf.st_dev);
38  uds.fastInsert(KIO::UDSEntry::UDS_INODE, statBuf.st_ino);
39 
40  mode_t type = statBuf.st_mode & S_IFMT;
41  mode_t access = statBuf.st_mode & 07777;
42 
43  uds.fastInsert(KIO::UDSEntry::UDS_SIZE, statBuf.st_size);
46  uds.fastInsert(KIO::UDSEntry::UDS_MODIFICATION_TIME, statBuf.st_mtime);
47  uds.fastInsert(KIO::UDSEntry::UDS_ACCESS_TIME, statBuf.st_atime);
48 #ifndef Q_OS_WIN
49  uds.fastInsert(KIO::UDSEntry::UDS_USER, m_userGroupCache.getUserName(KUserId(statBuf.st_uid)));
50  uds.fastInsert(KIO::UDSEntry::UDS_GROUP, m_userGroupCache.getGroupName(KGroupId(statBuf.st_gid)));
51 #else
52 #pragma message("TODO: st_uid and st_gid are always zero, use GetSecurityInfo to find the owner")
53 #endif
54 
55  QUrl url = QUrl::fromLocalFile(filePath);
59 
60  return uds;
61 }
62 
63 }
64 #endif
Type type(const QSqlDatabase &db)
QByteArray encodeName(const QString &fileName)
QString url(QUrl::FormattingOptions options) const const
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
QUrl fromLocalFile(const QString &localFile)
QString fileName(QUrl::ComponentFormattingOptions options) const const
void reserve(int size)
void fastInsert(uint field, const QString &value)
int access(const QString &path, int mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.