Warning, file /frameworks/kio/src/ioslaves/file/file_p.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2017 Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef FILE_P_H
0008 #define FILE_P_H
0009 
0010 #include <cerrno>
0011 
0012 enum ActionType {
0013     UNKNOWN,
0014     CHMOD = 1,
0015     CHOWN,
0016     DEL,
0017     MKDIR,
0018     OPEN,
0019     OPENDIR,
0020     RENAME,
0021     RMDIR,
0022     SYMLINK,
0023     UTIME,
0024     COPY,
0025 };
0026 
0027 /**
0028  * PrivilegeOperationReturnValue encapsulates the return value from execWithElevatedPrivilege() in a convenient way.
0029  * Warning, this class will cast to an int that is zero on success and non-zero on failure. This unusual solution allows
0030  * to write kioslave code like this:
0031 
0032 if (!dir.rmdir(itemPath)) {
0033     if (auto ret = execWithElevatedPrivilege(RMDIR, itemPath)) {
0034         if (!ret.wasCanceled()) {
0035             error(KIO::ERR_CANNOT_DELETE, itemPath);
0036         }
0037         return false;
0038     }
0039 }
0040 // directory successfully removed, continue with the next operation
0041 */
0042 class PrivilegeOperationReturnValue
0043 {
0044 public:
0045     static PrivilegeOperationReturnValue success()
0046     {
0047         return PrivilegeOperationReturnValue{false, 0};
0048     }
0049     static PrivilegeOperationReturnValue canceled()
0050     {
0051         return PrivilegeOperationReturnValue{true, ECANCELED};
0052     }
0053     static PrivilegeOperationReturnValue failure(int error)
0054     {
0055         return PrivilegeOperationReturnValue{false, error};
0056     }
0057     operator int() const
0058     {
0059         return m_error;
0060     }
0061     bool operator==(int error) const
0062     {
0063         return m_error == error;
0064     }
0065     bool wasCanceled() const
0066     {
0067         return m_canceled;
0068     }
0069 
0070 private:
0071     PrivilegeOperationReturnValue(bool canceled, int error)
0072         : m_canceled(canceled)
0073         , m_error(error)
0074     {
0075     }
0076     const bool m_canceled;
0077     const int m_error;
0078 };
0079 
0080 #endif