File indexing completed on 2024-10-06 12:21:28

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KIO_KIOGLOBAL_P_H
0009 #define KIO_KIOGLOBAL_P_H
0010 
0011 #include "kiocore_export.h"
0012 #include <qplatformdefs.h>
0013 
0014 #include <KUser>
0015 
0016 #ifdef Q_OS_WIN
0017 // windows just sets the mode_t access rights bits to the same value for user+group+other.
0018 // This means using the Linux values here is fine.
0019 #ifndef S_IRUSR
0020 #define S_IRUSR 0400
0021 #endif
0022 #ifndef S_IRGRP
0023 #define S_IRGRP 0040
0024 #endif
0025 #ifndef S_IROTH
0026 #define S_IROTH 0004
0027 #endif
0028 
0029 #ifndef S_IWUSR
0030 #define S_IWUSR 0200
0031 #endif
0032 #ifndef S_IWGRP
0033 #define S_IWGRP 0020
0034 #endif
0035 #ifndef S_IWOTH
0036 #define S_IWOTH 0002
0037 #endif
0038 
0039 #ifndef S_IXUSR
0040 #define S_IXUSR 0100
0041 #endif
0042 #ifndef S_IXGRP
0043 #define S_IXGRP 0010
0044 #endif
0045 #ifndef S_IXOTH
0046 #define S_IXOTH 0001
0047 #endif
0048 
0049 #ifndef S_IRWXU
0050 #define S_IRWXU S_IRUSR | S_IWUSR | S_IXUSR
0051 #endif
0052 #ifndef S_IRWXG
0053 #define S_IRWXG S_IRGRP | S_IWGRP | S_IXGRP
0054 #endif
0055 #ifndef S_IRWXO
0056 #define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH
0057 #endif
0058 Q_STATIC_ASSERT(S_IRUSR == _S_IREAD && S_IWUSR == _S_IWRITE && S_IXUSR == _S_IEXEC);
0059 
0060 // these three will never be set in st_mode
0061 #ifndef S_ISUID
0062 #define S_ISUID 04000 // SUID bit does not exist on windows
0063 #endif
0064 #ifndef S_ISGID
0065 #define S_ISGID 02000 // SGID bit does not exist on windows
0066 #endif
0067 #ifndef S_ISVTX
0068 #define S_ISVTX 01000 // sticky bit does not exist on windows
0069 #endif
0070 
0071 // Windows does not have S_IFBLK and S_IFSOCK, just use the Linux values, they won't conflict
0072 #ifndef S_IFBLK
0073 #define S_IFBLK 0060000
0074 #endif
0075 #ifndef S_IFSOCK
0076 #define S_IFSOCK 0140000
0077 #endif
0078 /** performs a QT_STAT and add QT_STAT_LNK to st_mode if the path is a symlink */
0079 KIOCORE_EXPORT int kio_windows_lstat(const char *path, QT_STATBUF *buffer);
0080 
0081 #ifndef QT_LSTAT
0082 #define QT_LSTAT kio_windows_lstat
0083 #endif
0084 
0085 #ifndef QT_STAT_LNK
0086 #define QT_STAT_LNK 0120000
0087 #endif // QT_STAT_LNK
0088 
0089 #endif // Q_OS_WIN
0090 
0091 namespace KIOPrivate
0092 {
0093 /** @return true if the process with given PID is currently running */
0094 KIOCORE_EXPORT bool isProcessAlive(qint64 pid);
0095 /** Send a terminate signal (SIGTERM on UNIX) to the process with given PID. */
0096 KIOCORE_EXPORT void sendTerminateSignal(qint64 pid);
0097 
0098 enum SymlinkType {
0099     GuessSymlinkType,
0100     FileSymlink,
0101     DirectorySymlink,
0102 };
0103 
0104 /** Creates a symbolic link at @p destination pointing to @p source
0105  * Unlike UNIX, Windows needs to know whether the symlink points to a file or a directory
0106  * when creating the link. This information can be passed in @p type. If @p type is not given
0107  * the windows code will guess the type based on the source file.
0108  * @note On Windows this requires the current user to have the SeCreateSymbolicLink privilege which
0109  * is usually only given to administrators.
0110  * @return true on success, false on error
0111  */
0112 KIOCORE_EXPORT bool createSymlink(const QString &source, const QString &destination, SymlinkType type = GuessSymlinkType);
0113 
0114 /** Changes the ownership of @p file (like chown()) */
0115 KIOCORE_EXPORT bool changeOwnership(const QString &file, KUserId newOwner, KGroupId newGroup);
0116 
0117 /** Returns an icon name for a standard path,
0118  * e.g. folder-pictures for any path in QStandardPaths::PicturesLocation */
0119 QString iconForStandardPath(const QString &localDirectory);
0120 }
0121 
0122 #endif // KIO_KIOGLOBAL_P_H