diff --git a/basestruct/CMakeLists.txt b/basestruct/CMakeLists.txt index be31f70..2db8439 100644 --- a/basestruct/CMakeLists.txt +++ b/basestruct/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +# SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. # # SPDX-License-Identifier: GPL-3.0-only @@ -12,6 +12,8 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets DBus REQUIRED) +# DConfig(动态日志规则)需要 DTK Core +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) set(CMAKE_CXX_STANDARD 14) @@ -26,6 +28,7 @@ set(BASESTRUCT_SRCS ${BASESTRUCT_SOURCES} ${BASESTRUCT_HEADERS} ) add_library(${PROJECT_NAME} STATIC ${BASESTRUCT_SRCS}) target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} Qt${QT_VERSION_MAJOR}::GuiPrivate ${PROJECT_BINARY_DIR} ) @@ -33,6 +36,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::DBus + Dtk${DTK_VERSION_MAJOR}::Core Threads::Threads ) diff --git a/basestruct/ddlog.h b/basestruct/ddlog.h new file mode 100644 index 0000000..d6fd46b --- /dev/null +++ b/basestruct/ddlog.h @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef DDLOG_H +#define DDLOG_H + +#include + +// 全项目统一的日志分类声明,便于 DConfig(org.deepin.dde.diskmanager) 按应用统一过滤。 +// 分类名必须以 org.deepin. 前缀、与 desktop 名(deepin-diskmanager)对应, +// 调试模式(deepin-debug-config)按 "org.deepin.dde.diskmanager*.debug" 等通配规则分级开关。 + +// 主程序 deepin-diskmanager(GUI 前端进程) +Q_DECLARE_LOGGING_CATEGORY(appLog) + +// 后台服务 deepin-diskmanager-service(systemd/D-Bus 激活的 root 守护进程) +Q_DECLARE_LOGGING_CATEGORY(serviceLog) + +// 公共基础库 basestruct(被主程序与后台服务共同链接,在两个进程中都会输出) +Q_DECLARE_LOGGING_CATEGORY(baseLog) + +#endif // DDLOG_H diff --git a/basestruct/deviceinfo.cpp b/basestruct/deviceinfo.cpp index 98846f4..a2adcc8 100644 --- a/basestruct/deviceinfo.cpp +++ b/basestruct/deviceinfo.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "deviceinfo.h" #include #include @@ -9,32 +10,32 @@ /*********************************** stCustest *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const stCustest &stcus) { - // qDebug() << "Starting stCustest serialization"; + // qCDebug(baseLog) << "Starting stCustest serialization"; argument.beginStructure(); argument << stcus.m_length << stcus.m_heads << stcus.m_path; argument.endStructure(); - // qDebug() << "Completed stCustest serialization"; + // qCDebug(baseLog) << "Completed stCustest serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, stCustest &stcus) { - // qDebug() << "Starting stCustest deserialization"; + // qCDebug(baseLog) << "Starting stCustest deserialization"; argument.beginStructure(); argument >> stcus.m_length >> stcus.m_heads >> stcus.m_path; argument.endStructure(); - // qDebug() << "Completed stCustest deserialization"; + // qCDebug(baseLog) << "Completed stCustest deserialization"; return argument; } /*********************************** HardDiskInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const HardDiskInfo &inhdinfo) { - // qDebug() << "Starting HardDiskInfo serialization"; + // qCDebug(baseLog) << "Starting HardDiskInfo serialization"; argument.beginStructure(); argument << inhdinfo.m_model << inhdinfo.m_vendor @@ -51,13 +52,13 @@ QDBusArgument &operator<<(QDBusArgument &argument, const HardDiskInfo &inhdinfo) << inhdinfo.m_firmwareVersion << inhdinfo.m_speed; argument.endStructure(); - // qDebug() << "Completed HardDiskInfo serialization"; + // qCDebug(baseLog) << "Completed HardDiskInfo serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, HardDiskInfo &inhdinfo) { - // qDebug() << "Starting HardDiskInfo deserialization"; + // qCDebug(baseLog) << "Starting HardDiskInfo deserialization"; argument.beginStructure(); argument >> inhdinfo.m_model >> inhdinfo.m_vendor @@ -74,13 +75,13 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, HardDiskInfo &inh >> inhdinfo.m_firmwareVersion >> inhdinfo.m_speed; argument.endStructure(); - // qDebug() << "Completed HardDiskInfo deserialization"; + // qCDebug(baseLog) << "Completed HardDiskInfo deserialization"; return argument; } /*********************************** HardDiskStatusInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const HardDiskStatusInfo &inhdinfo) { - // qDebug() << "Starting HardDiskStatusInfo serialization"; + // qCDebug(baseLog) << "Starting HardDiskStatusInfo serialization"; argument.beginStructure(); argument << inhdinfo.m_id << inhdinfo.m_attributeName @@ -93,12 +94,12 @@ QDBusArgument &operator<<(QDBusArgument &argument, const HardDiskStatusInfo &inh << inhdinfo.m_whenFailed << inhdinfo.m_rawValue; argument.endStructure(); - // qDebug() << "Completed HardDiskStatusInfo serialization"; + // qCDebug(baseLog) << "Completed HardDiskStatusInfo serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, HardDiskStatusInfo &inhdinfo) { - // qDebug() << "Starting HardDiskStatusInfo deserialization"; + // qCDebug(baseLog) << "Starting HardDiskStatusInfo deserialization"; argument.beginStructure(); argument >> inhdinfo.m_id >> inhdinfo.m_attributeName @@ -112,13 +113,13 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, HardDiskStatusInf >> inhdinfo.m_rawValue; argument.endStructure(); - // qDebug() << "Completed HardDiskStatusInfo deserialization"; + // qCDebug(baseLog) << "Completed HardDiskStatusInfo deserialization"; return argument; } /*********************************** DeviceInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const DeviceInfo &info) { - // qDebug() << "Starting DeviceInfo serialization"; + // qCDebug(baseLog) << "Starting DeviceInfo serialization"; argument.beginStructure(); argument << info.m_length << info.m_heads @@ -142,13 +143,13 @@ QDBusArgument &operator<<(QDBusArgument &argument, const DeviceInfo &info) << static_cast(info.m_luksFlag) << info.m_crySupport; argument.endStructure(); - // qDebug() << "Completed DeviceInfo serialization"; + // qCDebug(baseLog) << "Completed DeviceInfo serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceInfo &info) { - // qDebug() << "Starting DeviceInfo deserialization"; + // qCDebug(baseLog) << "Starting DeviceInfo deserialization"; argument.beginStructure(); int flag = 0; int flag2 = 0; @@ -176,26 +177,26 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceInfo &info) info.m_vgFlag = static_cast(flag); info.m_luksFlag = static_cast(flag2); argument.endStructure(); - // qDebug() << "Completed DeviceInfo deserialization"; + // qCDebug(baseLog) << "Completed DeviceInfo deserialization"; return argument; } DeviceInfo::DeviceInfo() : m_readonly(false) { - qDebug() << "Initializing DeviceInfo with default values"; + qCDebug(baseLog) << "Initializing DeviceInfo with default values"; m_length = m_heads = m_sectors = m_cylinders = m_cylsize = m_sectorSize = m_maxPrims = m_highestBusy = m_maxPartitionNameLength = 0; m_path = m_model = m_serialNumber = m_disktype = m_mediaType = m_interface = QString(""); m_partition.clear(); m_vgFlag = LVM_FLAG_NOT_PV; m_vglist.clear(); m_luksFlag = LUKSFlag::NOT_CRYPT_LUKS; - qDebug() << "DeviceInfo initialization completed"; + qCDebug(baseLog) << "DeviceInfo initialization completed"; } /*********************************** WipeAction *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const WipeAction &data) { - // qDebug() << "Starting WipeAction serialization"; + // qCDebug(baseLog) << "Starting WipeAction serialization"; argument.beginStructure(); argument << data.m_fstype << data.m_path @@ -209,13 +210,13 @@ QDBusArgument &operator<<(QDBusArgument &argument, const WipeAction &data) << data.m_decryptStr << data.m_dmName; argument.endStructure(); - // qDebug() << "Completed WipeAction serialization"; + // qCDebug(baseLog) << "Completed WipeAction serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, WipeAction &data) { - // qDebug() << "Starting WipeAction deserialization"; + // qCDebug(baseLog) << "Starting WipeAction deserialization"; argument.beginStructure(); int flag1, flag2; argument >> data.m_fstype @@ -232,6 +233,6 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, WipeAction &data) data.m_luksFlag = static_cast(flag1); data.m_crypt = static_cast(flag2); argument.endStructure(); - // qDebug() << "Completed WipeAction deserialization"; + // qCDebug(baseLog) << "Completed WipeAction deserialization"; return argument; } diff --git a/basestruct/logger.cpp b/basestruct/logger.cpp new file mode 100644 index 0000000..2d1b487 --- /dev/null +++ b/basestruct/logger.cpp @@ -0,0 +1,88 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-only + +#include "logger.h" +#include "ddlog.h" +#include +#include + +#ifdef DTKCORE_CLASS_DConfigFile +#include +#endif +DCORE_USE_NAMESPACE + +// 分类定义:主程序 / 后台服务 / 公共库 basestruct 各自独立分类, +// 规则 "org.deepin.dde.diskmanager*.debug" 通配三者(* 可跨 '.' 匹配) +Q_LOGGING_CATEGORY(appLog, "org.deepin.dde.diskmanager") +Q_LOGGING_CATEGORY(serviceLog, "org.deepin.dde.diskmanager.service") +Q_LOGGING_CATEGORY(baseLog, "org.deepin.dde.diskmanager.basestruct") + +MLogger::MLogger(QObject *parent) + : QObject(parent), m_rules("") +#ifdef DTKCORE_CLASS_DConfigFile + , m_config(nullptr) +#endif +{ + QByteArray logRules = qgetenv("QT_LOGGING_RULES"); + // qunsetenv 之前一定不要有任何日志打印,否则取消环境变量设置不会生效(大坑) + qunsetenv("QT_LOGGING_RULES"); + + // set env + m_rules = logRules; + +#ifdef DTKCORE_CLASS_DConfigFile + // set dconfig + m_config = DConfig::create("org.deepin.dde.diskmanager", "org.deepin.dde.diskmanager"); + if (m_config) { + logRules = m_config->value("log_rules").toByteArray(); + appendRules(logRules); + setRules(m_rules); + + // 监听 dconfig 变更,实现调试模式运行中动态调整 + connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) { + if (key == "log_rules") { + setRules(m_config->value(key).toByteArray()); + } + }); + } else { + // dconfig meta 未安装时退回环境变量规则,保证基础日志能力可用 + setRules(m_rules); + } +#else + setRules(m_rules); +#endif +} + +MLogger::~MLogger() +{ +#ifdef DTKCORE_CLASS_DConfigFile + if (m_config) { + m_config->deleteLater(); + } +#endif +} + +void MLogger::setRules(const QString &rules) +{ + auto tmpRules = rules; + // Qt 限制:setFilterRules 的分隔符必须是 '\n',不能是 ';' + m_rules = tmpRules.replace(";", "\n"); + QLoggingCategory::setFilterRules(m_rules); +} + +void MLogger::appendRules(const QString &rules) +{ + QString tmpRules = rules; + tmpRules = tmpRules.replace(";", "\n"); + auto tmplist = tmpRules.split('\n'); + for (int i = 0; i < tmplist.count(); i++) + if (m_rules.contains(tmplist.at(i))) { + tmplist.removeAt(i); + i--; + } + if (tmplist.isEmpty()) + return; + m_rules.isEmpty() ? m_rules = tmplist.join("\n") + : m_rules += "\n" + tmplist.join("\n"); +} diff --git a/basestruct/logger.h b/basestruct/logger.h new file mode 100644 index 0000000..9be3325 --- /dev/null +++ b/basestruct/logger.h @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef BASESTRUCT_LOGGER_H +#define BASESTRUCT_LOGGER_H + +#include +#include + +#ifdef DTKCORE_CLASS_DConfigFile +DCORE_BEGIN_NAMESPACE +class DConfig; +DCORE_END_NAMESPACE +#endif + +/** + * @brief 动态日志规则监听器 + * + * 参考 deepin-reader 的 MLogger 实现: + * 1. 读取环境变量 QT_LOGGING_RULES 后立即 qunsetenv(必须在任何日志打印之前, + * 否则取消环境变量设置不生效),保证外部注入的规则仍然有效; + * 2. 读取 DConfig(org.deepin.dde.diskmanager) 的 log_rules 默认规则; + * 3. 监听 DConfig valueChanged,实现调试模式运行中动态调整日志级别。 + * + * 使用方式:在 main() 中、Application 实例化之前创建一次(先于任何日志打印): + * MLogger logger; + */ +class MLogger : public QObject +{ + Q_OBJECT +public: + explicit MLogger(QObject *parent = nullptr); + ~MLogger(); + + inline QString rules() const { return m_rules; } + void setRules(const QString &rules); + +private: + void appendRules(const QString &rules); + +private: + QString m_rules; +#ifdef DTKCORE_CLASS_DConfigFile + Dtk::Core::DConfig *m_config; +#endif +}; + +#endif // BASESTRUCT_LOGGER_H diff --git a/basestruct/luksstruct.cpp b/basestruct/luksstruct.cpp index 30f8f51..c4e182c 100644 --- a/basestruct/luksstruct.cpp +++ b/basestruct/luksstruct.cpp @@ -1,8 +1,9 @@ // Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "luksstruct.h" #include @@ -10,42 +11,42 @@ /*********************************** CRYPT_CIPHER_Support *********************************************/ bool CRYPT_CIPHER_Support::supportDecrypt(CRYPT_CIPHER_Support::Support x) { - qDebug() << "Checking decrypt support for cipher type:" << x; + qCDebug(baseLog) << "Checking decrypt support for cipher type:" << x; return (supportAllcrypt(x) || (((x) & 0xFFFF) == (CRYPT_CIPHER_Support::Support::DECRYPT))); } bool CRYPT_CIPHER_Support::supportEncrypt(CRYPT_CIPHER_Support::Support x) { - qDebug() << "Checking encrypt support for cipher type:" << x; + qCDebug(baseLog) << "Checking encrypt support for cipher type:" << x; return (supportAllcrypt(x) || (((x) & 0xFFFF) == (CRYPT_CIPHER_Support::Support::ENCRYPT))); } bool CRYPT_CIPHER_Support::notSupportCrypt(CRYPT_CIPHER_Support::Support x) { - qDebug() << "Checking no support for cipher type:" << x; + qCDebug(baseLog) << "Checking no support for cipher type:" << x; return ((x) & 0xFFFF) == (CRYPT_CIPHER_Support::Support::NOT_SUPPORT); } bool CRYPT_CIPHER_Support::supportAllcrypt(CRYPT_CIPHER_Support::Support x) { - qDebug() << "Checking all crypt support for cipher type:" << x; + qCDebug(baseLog) << "Checking all crypt support for cipher type:" << x; return ((x) & 0xFFFF) == (CRYPT_CIPHER_Support::Support::CRYPT_ALL); } QDBusArgument &operator<<(QDBusArgument &argument, const CRYPT_CIPHER_Support &data) { - // qDebug() << "Starting CRYPT_CIPHER_Support serialization"; + // qCDebug(baseLog) << "Starting CRYPT_CIPHER_Support serialization"; argument.beginStructure(); argument << static_cast(data.aes_xts_plain64) << static_cast(data.sm4_xts_plain64); argument.endStructure(); - // qDebug() << "Completed CRYPT_CIPHER_Support serialization"; + // qCDebug(baseLog) << "Completed CRYPT_CIPHER_Support serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, CRYPT_CIPHER_Support &data) { - // qDebug() << "Starting CRYPT_CIPHER_Support deserialization"; + // qCDebug(baseLog) << "Starting CRYPT_CIPHER_Support deserialization"; argument.beginStructure(); int aes, sm4; argument >> aes @@ -53,13 +54,13 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, CRYPT_CIPHER_Supp data.aes_xts_plain64 = static_cast(aes); data.sm4_xts_plain64 = static_cast(sm4); argument.endStructure(); - // qDebug() << "Completed CRYPT_CIPHER_Support deserialization"; + // qCDebug(baseLog) << "Completed CRYPT_CIPHER_Support deserialization"; return argument; } /*********************************** LUKS_MapperInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LUKS_MapperInfo &data) { - // qDebug() << "Starting LUKS_MapperInfo serialization"; + // qCDebug(baseLog) << "Starting LUKS_MapperInfo serialization"; argument.beginStructure(); argument << static_cast(data.m_luksFs) << data.m_mountPoints @@ -79,13 +80,13 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LUKS_MapperInfo &data) << data.m_fsLimits.min_size << data.m_fileSystemLabel; argument.endStructure(); - // qDebug() << "Completed LUKS_MapperInfo serialization"; + // qCDebug(baseLog) << "Completed LUKS_MapperInfo serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, LUKS_MapperInfo &data) { - // qDebug() << "Starting LUKS_MapperInfo deserialization"; + // qCDebug(baseLog) << "Starting LUKS_MapperInfo deserialization"; argument.beginStructure(); int luksFlag, vgFlag, cipher; argument >> luksFlag @@ -109,13 +110,13 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LUKS_MapperInfo & data.m_vgflag = static_cast(vgFlag); data.m_crypt = static_cast(cipher); argument.endStructure(); - // qDebug() << "Completed LUKS_MapperInfo deserialization"; + // qCDebug(baseLog) << "Completed LUKS_MapperInfo deserialization"; return argument; } /*********************************** LUKS_INFO *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LUKS_INFO &data) { - // qDebug() << "Starting LUKS_INFO serialization"; + // qCDebug(baseLog) << "Starting LUKS_INFO serialization"; argument.beginStructure(); argument << data.m_mapper << data.m_devicePath @@ -132,13 +133,13 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LUKS_INFO &data) << data.m_Suspend << data.m_fileSystemLabel; argument.endStructure(); - // qDebug() << "Completed LUKS_INFO serialization"; + // qCDebug(baseLog) << "Completed LUKS_INFO serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, LUKS_INFO &data) { - // qDebug() << "Starting LUKS_INFO deserialization"; + // qCDebug(baseLog) << "Starting LUKS_INFO deserialization"; argument.beginStructure(); int crypt, cryptErr; argument >> data.m_mapper @@ -158,26 +159,26 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LUKS_INFO &data) data.m_crypt = static_cast(crypt); data.m_cryptErr = static_cast(cryptErr); argument.endStructure(); - // qDebug() << "Completed LUKS_INFO deserialization"; + // qCDebug(baseLog) << "Completed LUKS_INFO deserialization"; return argument; } /*********************************** LUKSMap ************************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LUKSMap &data) { - // qDebug() << "Starting LUKSMap serialization"; + // qCDebug(baseLog) << "Starting LUKSMap serialization"; argument.beginStructure(); argument << data.m_luksMap << data.m_mapper << static_cast(data.m_cryErr) << data.m_cryptSuuport; argument.endStructure(); - // qDebug() << "Completed LUKSMap serialization"; + // qCDebug(baseLog) << "Completed LUKSMap serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, LUKSMap &data) { - // qDebug() << "Starting LUKSMap deserialization"; + // qCDebug(baseLog) << "Starting LUKSMap deserialization"; argument.beginStructure(); int cryptErr; argument >> data.m_luksMap @@ -186,82 +187,82 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LUKSMap &data) >> data.m_cryptSuuport; data.m_cryErr = static_cast(cryptErr); argument.endStructure(); - // qDebug() << "Completed LUKSMap deserialization"; + // qCDebug(baseLog) << "Completed LUKSMap deserialization"; return argument; } LUKSMap::LUKSMap() { - qDebug() << "LUKSMap object created"; + qCDebug(baseLog) << "LUKSMap object created"; } bool LUKSMap::mapperExists(const QString &path) const { - qDebug() << "Checking mapper existence for path:" << path; + qCDebug(baseLog) << "Checking mapper existence for path:" << path; if (itemExists(path, m_mapper)) { - qDebug() << "Mapper exists for path:" << path; + qCDebug(baseLog) << "Mapper exists for path:" << path; return true; } foreach (const LUKS_MapperInfo &tmp, m_mapper) { if (tmp.m_dmPath == path) { - // qDebug() << "Mapper found by dmPath for path:" << path; + // qCDebug(baseLog) << "Mapper found by dmPath for path:" << path; return true; } } - qDebug() << "Mapper does not exist for path:" << path; + qCDebug(baseLog) << "Mapper does not exist for path:" << path; return false; } QString LUKSMap::getMapperPath(const QString &devPath) const { - qDebug() << "Getting mapper path for device:" << devPath; + qCDebug(baseLog) << "Getting mapper path for device:" << devPath; QString mapperPath = getItem(devPath, m_mapper).m_dmPath; - qDebug() << "Mapper path for device" << devPath << "is:" << mapperPath; + qCDebug(baseLog) << "Mapper path for device" << devPath << "is:" << mapperPath; return mapperPath; } QString LUKSMap::getDevPath(const QString &mapper) const { - qDebug() << "Getting device path for mapper:" << mapper; + qCDebug(baseLog) << "Getting device path for mapper:" << mapper; QString devPath = getMapper(mapper).m_devicePath; - qDebug() << "Device path for mapper" << mapper << "is:" << devPath; + qCDebug(baseLog) << "Device path for mapper" << mapper << "is:" << devPath; return devPath; } bool LUKSMap::mapperOfDevice(const QString &mapper, const QString &dev) const { - qDebug() << "Checking if mapper" << mapper << "belongs to device" << dev; + qCDebug(baseLog) << "Checking if mapper" << mapper << "belongs to device" << dev; bool isMatch = mapperExists(mapper) ? getMapper(mapper).m_devicePath == dev : false; - qDebug() << "Mapper" << mapper << (isMatch ? "matches" : "does not match") << "device" << dev; + qCDebug(baseLog) << "Mapper" << mapper << (isMatch ? "matches" : "does not match") << "device" << dev; return isMatch; } bool LUKSMap::deviceExists(const QString &dev) const { - qDebug() << "Checking device existence:" << dev; + qCDebug(baseLog) << "Checking device existence:" << dev; bool exists = itemExists(dev, m_luksMap); - qDebug() << "Device" << dev << (exists ? "exists" : "does not exist") << "in LUKS map"; + qCDebug(baseLog) << "Device" << dev << (exists ? "exists" : "does not exist") << "in LUKS map"; return exists; } LUKS_MapperInfo LUKSMap::getMapper(const QString &path) const { - // qDebug() << "Getting mapper for path:" << path; + // qCDebug(baseLog) << "Getting mapper for path:" << path; foreach (const LUKS_MapperInfo &tmp, m_mapper) { if (tmp.m_dmPath == path || tmp.m_devicePath == path) { - qDebug() << "Mapper found for path:" << path; + qCDebug(baseLog) << "Mapper found for path:" << path; return tmp; } } - qDebug() << "No mapper found for path:" << path; + qCDebug(baseLog) << "No mapper found for path:" << path; return LUKS_MapperInfo(); } LUKS_MapperInfo LUKSMap::getMapper(const LUKS_MapperInfo &mapper) const { - // qDebug() << "Getting mapper for device path:" << mapper.m_devicePath; + // qCDebug(baseLog) << "Getting mapper for device path:" << mapper.m_devicePath; return getMapper(mapper.m_devicePath); } @@ -269,13 +270,13 @@ LUKS_MapperInfo LUKSMap::getMapper(const LUKS_MapperInfo &mapper) const bool LUKSMap::luksExists(const QString &devPath) const { bool exists = itemExists(devPath, m_luksMap); - qDebug() << "LUKS" << (exists ? "exists" : "does not exist") << "for device path:" << devPath; + qCDebug(baseLog) << "LUKS" << (exists ? "exists" : "does not exist") << "for device path:" << devPath; return exists; } LUKS_INFO LUKSMap::getLUKS(const QString &path) const { - // qDebug() << "Getting LUKS for path:" << path; + // qCDebug(baseLog) << "Getting LUKS for path:" << path; QString devicePath = deviceExists(path) ? path : getDevPath(path); return getItem(devicePath, m_luksMap); } @@ -283,14 +284,14 @@ LUKS_INFO LUKSMap::getLUKS(const QString &path) const template bool LUKSMap::itemExists(const QString &str, const QMap &containers)const { - // qDebug() << "Checking existence of item:" << str; + // qCDebug(baseLog) << "Checking existence of item:" << str; return containers.find(str) != containers.end(); } template T LUKSMap::getItem(const QString &str, const QMap &containers)const { - // qDebug() << "Getting item:" << str; + // qCDebug(baseLog) << "Getting item:" << str; return itemExists(str, containers) ? *containers.find(str) : T(); } diff --git a/basestruct/lvmstruct.cpp b/basestruct/lvmstruct.cpp index e518b5a..d084a7d 100644 --- a/basestruct/lvmstruct.cpp +++ b/basestruct/lvmstruct.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "lvmstruct.h" #include @@ -9,22 +10,22 @@ /*********************************** PVData *********************************************/ bool PVData::operator<(const PVData &tmp) const { - // qDebug() << "Entering PVData::operator<"; + // qCDebug(baseLog) << "Entering PVData::operator<"; if (m_type == DevType::DEV_UNALLOCATED_PARTITION) { - // qDebug() << "Comparing unallocated partition"; + // qCDebug(baseLog) << "Comparing unallocated partition"; return m_devicePath < tmp.m_devicePath || m_startSector < tmp.m_startSector || m_endSector < tmp.m_endSector || m_diskPath < tmp.m_diskPath || m_sectorSize < tmp.m_sectorSize; } - // qDebug() << "Comparing allocated partition"; + // qCDebug(baseLog) << "Comparing allocated partition"; return m_devicePath < tmp.m_devicePath || m_diskPath < tmp.m_diskPath; } bool PVData::operator==(const PVData &tmp) const { - // qDebug() << "Entering PVData::operator=="; + // qCDebug(baseLog) << "Entering PVData::operator=="; return m_devicePath == tmp.m_devicePath && m_startSector == tmp.m_startSector && m_endSector == tmp.m_endSector @@ -36,7 +37,7 @@ bool PVData::operator==(const PVData &tmp) const QDBusArgument &operator<<(QDBusArgument &argument, const PVData &data) { - // qDebug() << "Entering operator<< for PVData"; + // qCDebug(baseLog) << "Entering operator<< for PVData"; argument.beginStructure(); argument << data.m_devicePath << data.m_startSector @@ -51,7 +52,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const PVData &data) const QDBusArgument &operator>>(const QDBusArgument &argument, PVData &data) { - // qDebug() << "Entering operator>> for PVData"; + // qCDebug(baseLog) << "Entering operator>> for PVData"; argument.beginStructure(); int pvAct, type; argument >> data.m_devicePath @@ -69,7 +70,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, PVData &data) /*********************************** CreateLVInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LVAction &data) { - // qDebug() << "Entering operator<< for LVAction"; + // qCDebug(baseLog) << "Entering operator<< for LVAction"; argument.beginStructure(); argument << data.m_vgName << data.m_lvName @@ -91,7 +92,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LVAction &data) const QDBusArgument &operator>>(const QDBusArgument &argument, LVAction &data) { - // qDebug() << "Entering operator>> for LVAction"; + // qCDebug(baseLog) << "Entering operator>> for LVAction"; argument.beginStructure(); int type, act, luksFlag, crypt; argument >> data.m_vgName @@ -118,7 +119,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LVAction &data) /*********************************** LVDATA *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LVData &data) { - // qDebug() << "Entering operator<< for LVData"; + // qCDebug(baseLog) << "Entering operator<< for LVData"; argument.beginStructure(); argument << data.m_lvName << data.m_lvPath @@ -130,7 +131,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LVData &data) const QDBusArgument &operator>>(const QDBusArgument &argument, LVData &data) { - // qDebug() << "Entering operator>> for LVData"; + // qCDebug(baseLog) << "Entering operator>> for LVData"; argument.beginStructure(); argument >> data.m_lvName >> data.m_lvPath @@ -142,7 +143,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LVData &data) /*********************************** VGDATA *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const VGData &data) { - // qDebug() << "Entering operator<< for VGData"; + // qCDebug(baseLog) << "Entering operator<< for VGData"; argument.beginStructure(); argument << data.m_vgName << data.m_vgSize @@ -155,7 +156,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const VGData &data) const QDBusArgument &operator>>(const QDBusArgument &argument, VGData &data) { - // qDebug() << "Entering operator>> for VGData"; + // qCDebug(baseLog) << "Entering operator>> for VGData"; argument.beginStructure(); argument >> data.m_vgName >> data.m_vgSize @@ -168,7 +169,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, VGData &data) /*********************************** PVRANGES *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const PVRanges &data) { - // qDebug() << "Entering operator<< for PVRanges"; + // qCDebug(baseLog) << "Entering operator<< for PVRanges"; argument.beginStructure(); argument << data.m_lvName << data.m_devPath @@ -183,7 +184,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const PVRanges &data) const QDBusArgument &operator>>(const QDBusArgument &argument, PVRanges &data) { - // qDebug() << "Entering operator>> for PVRanges"; + // qCDebug(baseLog) << "Entering operator>> for PVRanges"; argument.beginStructure(); argument >> data.m_lvName >> data.m_devPath @@ -198,7 +199,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, PVRanges &data) /*********************************** PVInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const PVInfo &data) { - // qDebug() << "Entering operator<< for PVInfo"; + // qCDebug(baseLog) << "Entering operator<< for PVInfo"; argument.beginStructure(); argument << data.m_pvFmt << data.m_vgName @@ -225,7 +226,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const PVInfo &data) const QDBusArgument &operator>>(const QDBusArgument &argument, PVInfo &data) { - // qDebug() << "Entering operator>> for PVInfo"; + // qCDebug(baseLog) << "Entering operator>> for PVInfo"; argument.beginStructure(); int err, devType; argument >> data.m_pvFmt @@ -255,7 +256,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, PVInfo &data) /*********************************** LVInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LVInfo &data) { - // qDebug() << "Entering operator<< for LVInfo"; + // qCDebug(baseLog) << "Entering operator<< for LVInfo"; argument.beginStructure(); argument << data.m_vgName << data.m_lvPath @@ -283,7 +284,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LVInfo &data) const QDBusArgument &operator>>(const QDBusArgument &argument, LVInfo &data) { - // qDebug() << "Entering operator>> for LVInfo"; + // qCDebug(baseLog) << "Entering operator>> for LVInfo"; argument.beginStructure(); int err, type, luksFlag; argument >> data.m_vgName @@ -315,7 +316,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LVInfo &data) /*********************************** VGInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const VGInfo &data) { - // qDebug() << "Entering operator<< for VGInfo"; + // qCDebug(baseLog) << "Entering operator<< for VGInfo"; argument.beginStructure(); argument << data.m_vgName << data.m_vgUuid @@ -339,7 +340,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const VGInfo &data) const QDBusArgument &operator>>(const QDBusArgument &argument, VGInfo &data) { - // qDebug() << "Entering operator>> for VGInfo"; + // qCDebug(baseLog) << "Entering operator>> for VGInfo"; argument.beginStructure(); int err, luksFlag; argument >> data.m_vgName @@ -366,19 +367,19 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, VGInfo &data) LVInfo VGInfo::getLVinfo(const QString &lvName) { - qDebug() << "VGInfo::getLVinfo - Enter, lvName:" << lvName; + qCDebug(baseLog) << "VGInfo::getLVinfo - Enter, lvName:" << lvName; foreach (const LVInfo &info, m_lvlist) { if (info.m_lvName == lvName) { return info; } } - qDebug() << "VGInfo::getLVinfo - Exit, lvName:" << lvName << "not found"; + qCDebug(baseLog) << "VGInfo::getLVinfo - Exit, lvName:" << lvName << "not found"; return LVInfo(); } bool VGInfo::lvInfoExists(const QString &lvName) { - qDebug() << "VGInfo::lvInfoExists - Checking lvName:" << lvName; + qCDebug(baseLog) << "VGInfo::lvInfoExists - Checking lvName:" << lvName; foreach (const LVInfo &info, m_lvlist) { if (info.m_lvName == lvName) { return true; @@ -389,10 +390,10 @@ bool VGInfo::lvInfoExists(const QString &lvName) bool VGInfo::isAllPV(QVector pvList) const { - qDebug() << "VGInfo::isAllPV - Checking pvList:" << pvList; + qCDebug(baseLog) << "VGInfo::isAllPV - Checking pvList:" << pvList; QVector list = m_pvInfo.keys().toVector(); if (pvList.size() < list.size()) { - qDebug() << "PV count mismatch"; + qCDebug(baseLog) << "PV count mismatch"; return false; } @@ -403,7 +404,7 @@ bool VGInfo::isAllPV(QVector pvList) const /*********************************** LVMInfo *********************************************/ QDBusArgument &operator<<(QDBusArgument &argument, const LVMInfo &data) { - // qDebug() << "Entering operator<< for LVMInfo"; + // qCDebug(baseLog) << "Entering operator<< for LVMInfo"; argument.beginStructure(); argument << data.m_pvInfo << data.m_vgInfo @@ -414,7 +415,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const LVMInfo &data) const QDBusArgument &operator>>(const QDBusArgument &argument, LVMInfo &data) { - // qDebug() << "Entering operator>> for LVMInfo"; + // qCDebug(baseLog) << "Entering operator>> for LVMInfo"; argument.beginStructure(); int err; argument >> data.m_pvInfo @@ -427,19 +428,19 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, LVMInfo &data) LVInfo LVMInfo::getLVInfo(const QString &lvPath) { - qDebug() << "LVMInfo::getLVInfo - Enter, lvPath:" << lvPath; + qCDebug(baseLog) << "LVMInfo::getLVInfo - Enter, lvPath:" << lvPath; // /dev/vg01/lv01 Or /dev/mapper/vg01-lv01 QStringList list = lvPath.split("/"); list.pop_front(); if (list.count() < 3) { - qWarning() << "LVMInfo::getLVInfo - Invalid lvPath format:" << lvPath; + qCWarning(baseLog) << "LVMInfo::getLVInfo - Invalid lvPath format:" << lvPath; return LVInfo(); } if (lvPath.contains("/dev/mapper/")) { QStringList list2 = list[2].split("-"); if (!vgExists(list2[0])) { - qWarning() << "LVMInfo::getLVInfo - VG not found for lvPath:" << lvPath; + qCWarning(baseLog) << "LVMInfo::getLVInfo - VG not found for lvPath:" << lvPath; return LVInfo(); } @@ -449,7 +450,7 @@ LVInfo LVMInfo::getLVInfo(const QString &lvPath) return lv; } } - qWarning() << "LVMInfo::getLVInfo - LV not found in mapper path:" << lvPath; + qCWarning(baseLog) << "LVMInfo::getLVInfo - LV not found in mapper path:" << lvPath; return LVInfo(); } return getLVInfo(list[1], list[2]); @@ -457,11 +458,11 @@ LVInfo LVMInfo::getLVInfo(const QString &lvPath) LVInfo LVMInfo::getLVInfo(const QString &vgName, const QString &lvName) { - qDebug() << "LVMInfo::getLVInfo - Enter, vgName:" << vgName << "lvName:" << lvName; + qCDebug(baseLog) << "LVMInfo::getLVInfo - Enter, vgName:" << vgName << "lvName:" << lvName; //判断lv是否存在 auto it = m_vgInfo.find(vgName); if (m_vgInfo.end() == it) { - qWarning() << "LVMInfo::getLVInfo - VG not found:" << vgName; + qCWarning(baseLog) << "LVMInfo::getLVInfo - VG not found:" << vgName; return LVInfo(); } return it.value().getLVinfo(lvName); @@ -469,61 +470,61 @@ LVInfo LVMInfo::getLVInfo(const QString &vgName, const QString &lvName) VGInfo LVMInfo::getVG(const QString &vgName) { - qDebug() << "LVMInfo::getVG - Enter, vgName:" << vgName; + qCDebug(baseLog) << "LVMInfo::getVG - Enter, vgName:" << vgName; return getItem(vgName, m_vgInfo); } VGInfo LVMInfo::getVG(const PVData &pv) { - qDebug() << "LVMInfo::getVG - Enter"; + qCDebug(baseLog) << "LVMInfo::getVG - Enter"; if (pvExists(pv)) { - qDebug() << "PV exists, getting PV info"; + qCDebug(baseLog) << "PV exists, getting PV info"; PVInfo info = getPV(pv); return getVG(info.m_vgName); } - qDebug() << "PV does not exist, returning empty VGInfo"; + qCDebug(baseLog) << "PV does not exist, returning empty VGInfo"; return VGInfo(); } VGInfo LVMInfo::getVG(const PVInfo &pv) { - // qDebug() << "LVMInfo::getVG - Enter"; + // qCDebug(baseLog) << "LVMInfo::getVG - Enter"; return getVG(pv.m_vgName); } PVInfo LVMInfo::getPV(const QString &pvPath) { - qDebug() << "LVMInfo::getPV - Enter, pvPath:" << pvPath; + qCDebug(baseLog) << "LVMInfo::getPV - Enter, pvPath:" << pvPath; return getItem(pvPath, m_pvInfo); } PVInfo LVMInfo::getPV(const PVData &pv) { - // qDebug() << "LVMInfo::getPV - Enter, pv:" << pv; + // qCDebug(baseLog) << "LVMInfo::getPV - Enter, pv:" << pv; return getPV(pv.m_devicePath); } QVector LVMInfo::getVGAllPV(const QString &vgName) { - // qDebug() << "LVMInfo::getVGAllPV - Enter, vgName:" << vgName; + // qCDebug(baseLog) << "LVMInfo::getVGAllPV - Enter, vgName:" << vgName; return vgExists(vgName) ? getVG(vgName).m_pvInfo.values().toVector() : QVector(); } QVector LVMInfo::getVGAllUsedPV(const QString &vgName) { - // qDebug() << "LVMInfo::getVGAllUsedPV - Enter, vgName:" << vgName; + // qCDebug(baseLog) << "LVMInfo::getVGAllUsedPV - Enter, vgName:" << vgName; return getVGPVList(vgName, true); } QVector LVMInfo::getVGAllUnUsedPV(const QString &vgName) { - // qDebug() << "LVMInfo::getVGAllUnUsedPV - Enter, vgName:" << vgName; + // qCDebug(baseLog) << "LVMInfo::getVGAllUnUsedPV - Enter, vgName:" << vgName; return getVGPVList(vgName, false); } QList LVMInfo::getVGOfDisk(const QString &vgName, const QString &disk) { - qDebug() << "LVMInfo::getVGOfDisk - Enter, vgName:" << vgName << "disk:" << disk; + qCDebug(baseLog) << "LVMInfo::getVGOfDisk - Enter, vgName:" << vgName << "disk:" << disk; QListlist; foreach (auto it, m_pvInfo) { //todo 要对这里进行优化 目前是比较是否包含磁盘路径字符串 @@ -531,23 +532,23 @@ QList LVMInfo::getVGOfDisk(const QString &vgName, const QString &disk) list.push_back(it.m_pvPath); } } - qDebug() << "LVMInfo::getVGOfDisk - Exiting, list:" << list; + qCDebug(baseLog) << "LVMInfo::getVGOfDisk - Exiting, list:" << list; return list; } QVector LVMInfo::getVGPVList(const QString &vgName, bool isUsed) { - qDebug() << "Entering LVMInfo::getVGPVList for VG:" << vgName << "isUsed:" << isUsed; + qCDebug(baseLog) << "Entering LVMInfo::getVGPVList for VG:" << vgName << "isUsed:" << isUsed; QVector pvList; if (vgExists(vgName)) { - qDebug() << "VG exists, getting PV list"; + qCDebug(baseLog) << "VG exists, getting PV list"; VGInfo vg = getVG(vgName); foreach (const PVInfo &pv, vg.m_pvInfo) { if (isUsed && pv.m_pvUsedPE > 0) { - qDebug() << "Checking if PV is used:" << pv.m_pvPath; + qCDebug(baseLog) << "Checking if PV is used:" << pv.m_pvPath; pvList.push_back(pv); } else if (!isUsed && pv.m_pvUsedPE == 0) { - qDebug() << "PV is not checked for usage, adding to list"; + qCDebug(baseLog) << "PV is not checked for usage, adding to list"; pvList.push_back(pv); } } @@ -557,11 +558,11 @@ QVector LVMInfo::getVGPVList(const QString &vgName, bool isUsed) bool LVMInfo::lvInfoExists(const QString &vgName, const QString &lvName) { - qDebug() << "LVMInfo::lvInfoExists - Enter, vgName:" << vgName << "lvName:" << lvName; + qCDebug(baseLog) << "LVMInfo::lvInfoExists - Enter, vgName:" << vgName << "lvName:" << lvName; //判断lv是否存在 auto it = m_vgInfo.find(vgName); if (m_vgInfo.end() == it) { - qDebug() << "LVMInfo::lvInfoExists - VG not found:" << vgName; + qCDebug(baseLog) << "LVMInfo::lvInfoExists - VG not found:" << vgName; return false; } return it.value().lvInfoExists(lvName); @@ -569,30 +570,30 @@ bool LVMInfo::lvInfoExists(const QString &vgName, const QString &lvName) bool LVMInfo::lvInfoExists(const QString &lvPath) { - qDebug() << "LVMInfo::lvInfoExists - Enter, lvPath:" << lvPath; + qCDebug(baseLog) << "LVMInfo::lvInfoExists - Enter, lvPath:" << lvPath; QStringList list = lvPath.split("/"); list.pop_front(); if (list.count() < 3) { - qWarning() << "LVMInfo::lvInfoExists - Invalid lvPath format:" << lvPath; + qCWarning(baseLog) << "LVMInfo::lvInfoExists - Invalid lvPath format:" << lvPath; return false; } if (lvPath.contains("/dev/mapper/")) { - qDebug() << "LVMInfo::lvInfoExists - Checking lvPath in mapper path:" << lvPath; + qCDebug(baseLog) << "LVMInfo::lvInfoExists - Checking lvPath in mapper path:" << lvPath; QStringList list2 = list[2].split("-"); if (!vgExists(list2[0])) { - qWarning() << "LVMInfo::lvInfoExists - VG not found in mapper path:" << lvPath; + qCWarning(baseLog) << "LVMInfo::lvInfoExists - VG not found in mapper path:" << lvPath; return false; } VGInfo vg = getVG(list2[0]); foreach (LVInfo lv, vg.m_lvlist) { if ("/dev/mapper/" + vg.m_vgName + "-" + lv.m_lvName == lvPath) { - qDebug() << "LVMInfo::lvInfoExists - LV found in mapper path:" << lvPath; + qCDebug(baseLog) << "LVMInfo::lvInfoExists - LV found in mapper path:" << lvPath; return true; } } - qWarning() << "LVMInfo::lvInfoExists - LV not found in mapper path:" << lvPath; + qCWarning(baseLog) << "LVMInfo::lvInfoExists - LV not found in mapper path:" << lvPath; return false; } return lvInfoExists(list[1], list[2]); @@ -600,39 +601,39 @@ bool LVMInfo::lvInfoExists(const QString &lvPath) bool LVMInfo::vgExists(const QString &vgName) { - qDebug() << "LVMInfo::vgExists - Checking vgName:" << vgName; + qCDebug(baseLog) << "LVMInfo::vgExists - Checking vgName:" << vgName; return itemExists(vgName, m_vgInfo); } bool LVMInfo::pvExists(const QString &pvPath) { - qDebug() << "LVMInfo::pvExists - Checking pvPath:" << pvPath; + qCDebug(baseLog) << "LVMInfo::pvExists - Checking pvPath:" << pvPath; return itemExists(pvPath, m_pvInfo); } bool LVMInfo::vgExists(const PVData &pv) { - // qDebug() << "LVMInfo::vgExists - Checking pv:" << pv; + // qCDebug(baseLog) << "LVMInfo::vgExists - Checking pv:" << pv; return pvExists(pv) ? vgExists(getPV(pv).m_vgName) : false; } bool LVMInfo::vgExists(const PVInfo &pv) { - // qDebug() << "LVMInfo::vgExists - Checking pv:" << pv; + // qCDebug(baseLog) << "LVMInfo::vgExists - Checking pv:" << pv; return vgExists(pv.m_vgName); } bool LVMInfo::pvExists(const PVData &pv) { - // qDebug() << "LVMInfo::pvExists - Checking pv:" << pv; + // qCDebug(baseLog) << "LVMInfo::pvExists - Checking pv:" << pv; return pvExists(pv.m_devicePath); } bool LVMInfo::pvOfVg(const QString &vgName, const QString &pvPath) { - qDebug() << "LVMInfo::pvOfVg - Enter, vgName:" << vgName << "pvPath:" << pvPath; + qCDebug(baseLog) << "LVMInfo::pvOfVg - Enter, vgName:" << vgName << "pvPath:" << pvPath; if (!vgExists(vgName)) { - qDebug() << "LVMInfo::pvOfVg - VG not found:" << vgName; + qCDebug(baseLog) << "LVMInfo::pvOfVg - VG not found:" << vgName; return false; } @@ -642,44 +643,44 @@ bool LVMInfo::pvOfVg(const QString &vgName, const QString &pvPath) bool LVMInfo::pvOfVg(const QString &vgName, const PVData &pv) { - qDebug() << "LVMInfo::pvOfVg - Checking vgName:" << vgName; + qCDebug(baseLog) << "LVMInfo::pvOfVg - Checking vgName:" << vgName; return pvOfVg(vgName, pv.m_devicePath); } bool LVMInfo::pvOfVg(const PVInfo &pv) { - // qDebug() << "LVMInfo::pvOfVg - Checking pv:" << pv; + // qCDebug(baseLog) << "LVMInfo::pvOfVg - Checking pv:" << pv; return pvOfVg(pv.m_vgName, pv.m_pvPath); } bool LVMInfo::pvOfVg(const VGInfo &vg, const PVInfo &pv) { - // qDebug() << "LVMInfo::pvOfVg - Checking pv:" << pv << "vg:" << vg; + // qCDebug(baseLog) << "LVMInfo::pvOfVg - Checking pv:" << pv << "vg:" << vg; return pvOfVg(vg.m_vgName, pv.m_pvPath); } bool LVMInfo::pvOfVg(const VGInfo &vg, const PVData &pv) { - // qDebug() << "LVMInfo::pvOfVg - Checking pv:" << pv << "vg:" << vg; + // qCDebug(baseLog) << "LVMInfo::pvOfVg - Checking pv:" << pv << "vg:" << vg; return pvOfVg(vg.m_vgName, pv.m_devicePath); } bool LVMInfo::pvOfVg(const QString &vgName, const PVInfo &pv) { - // qDebug() << "LVMInfo::pvOfVg - Checking pv:" << pv << "vgName:" << vgName; + // qCDebug(baseLog) << "LVMInfo::pvOfVg - Checking pv:" << pv << "vgName:" << vgName; return pvOfVg(vgName, pv.m_pvPath); } template T LVMInfo:: getItem(const QString &str, const QMap &containers) { - // qDebug() << "LVMInfo::getItem - Enter, str:" << str << "containers:" << containers; + // qCDebug(baseLog) << "LVMInfo::getItem - Enter, str:" << str << "containers:" << containers; return itemExists(str, containers) ? *containers.find(str) : T(); } template bool LVMInfo::itemExists(const QString &str, const QMap &containers) { - // qDebug() << "LVMInfo::itemExists - Enter, str:" << str << "containers:" << containers; + // qCDebug(baseLog) << "LVMInfo::itemExists - Enter, str:" << str << "containers:" << containers; return containers.find(str) != containers.end(); } diff --git a/basestruct/partitioninfo.cpp b/basestruct/partitioninfo.cpp index 39a3fa2..eaf2b6b 100644 --- a/basestruct/partitioninfo.cpp +++ b/basestruct/partitioninfo.cpp @@ -1,8 +1,9 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "partitioninfo.h" #include @@ -13,7 +14,7 @@ PartitionInfo::PartitionInfo() , m_busy(false) , m_fileSystemReadOnly(false) { - qDebug() << "PartitionInfo constructor"; + qCDebug(baseLog) << "PartitionInfo constructor"; //inside_extended = busy = fs_readonly = false; m_devicePath = m_uuid = m_name = m_path = m_fileSystemLabel = ""; m_partitionNumber = m_type = m_status = m_alignment = m_fileSystemType = 0; @@ -25,39 +26,39 @@ PartitionInfo::PartitionInfo() Sector PartitionInfo::getSectorLength() const { - qDebug() << "PartitionInfo::getSectorLength"; + qCDebug(baseLog) << "PartitionInfo::getSectorLength"; if (m_sectorStart >= 0 && m_sectorEnd >= 0) { - qDebug() << "PartitionInfo::getSectorLength - Valid sector range"; + qCDebug(baseLog) << "PartitionInfo::getSectorLength - Valid sector range"; return m_sectorEnd - m_sectorStart + 1; } else { - qWarning() << "PartitionInfo::getSectorLength - Invalid sector range"; + qCWarning(baseLog) << "PartitionInfo::getSectorLength - Invalid sector range"; return -1; } } Byte_Value PartitionInfo::getByteLength() const { - qDebug() << "PartitionInfo::getByteLength"; + qCDebug(baseLog) << "PartitionInfo::getByteLength"; if (getSectorLength() >= 0) { - qDebug() << "PartitionInfo::getByteLength - Valid sector range"; + qCDebug(baseLog) << "PartitionInfo::getByteLength - Valid sector range"; return getSectorLength() * m_sectorSize; } else { - qWarning() << "PartitionInfo::getByteLength - Invalid sector range"; + qCWarning(baseLog) << "PartitionInfo::getByteLength - Invalid sector range"; return -1; } } bool PartitionInfo::operator==(const PartitionInfo &info) const { - // qDebug() << "PartitionInfo::operator=="; + // qCDebug(baseLog) << "PartitionInfo::operator=="; return m_devicePath == info.m_devicePath && m_partitionNumber == info.m_partitionNumber && m_sectorStart == info.m_sectorStart && m_type == info.m_type; } QDBusArgument &operator<<(QDBusArgument &argument, const PartitionInfo &info) { - // qDebug() << "Starting PartitionInfo serialization"; + // qCDebug(baseLog) << "Starting PartitionInfo serialization"; argument.beginStructure(); - // qDebug() << "Serializing PartitionInfo fields"; + // qCDebug(baseLog) << "Serializing PartitionInfo fields"; argument << info.m_devicePath << info.m_partitionNumber << info.m_type @@ -92,15 +93,15 @@ QDBusArgument &operator<<(QDBusArgument &argument, const PartitionInfo &info) << info.m_decryptStr << info.m_dmName;; argument.endStructure(); - // qDebug() << "Completed PartitionInfo serialization"; + // qCDebug(baseLog) << "Completed PartitionInfo serialization"; return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, PartitionInfo &info) { - // qDebug() << "Starting PartitionInfo deserialization"; + // qCDebug(baseLog) << "Starting PartitionInfo deserialization"; argument.beginStructure(); - // qDebug() << "Deserializing PartitionInfo fields"; + // qCDebug(baseLog) << "Deserializing PartitionInfo fields"; int flag = 0; int flag2 = 0; int crypt = 0; @@ -141,6 +142,6 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, PartitionInfo &in info.m_luksFlag = static_cast(flag2); info.m_crypt = static_cast(crypt); argument.endStructure(); - // qDebug() << "Completed PartitionInfo deserialization"; + // qCDebug(baseLog) << "Completed PartitionInfo deserialization"; return argument; } diff --git a/basestruct/utils.cpp b/basestruct/utils.cpp index 25964d3..fa637c0 100644 --- a/basestruct/utils.cpp +++ b/basestruct/utils.cpp @@ -1,8 +1,9 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "lvmstruct.h" #include "utils.h" @@ -19,7 +20,7 @@ Utils::Utils() { - qDebug() << "Utils constructor"; + qCDebug(baseLog) << "Utils constructor"; } static QStringList parseCombinedArgString(const QString &program) @@ -64,9 +65,9 @@ static QStringList parseCombinedArgString(const QString &program) QString Utils::findProgramInPath(const QString &proName) { - qDebug() << "Utils::findProgramInPath----" << proName; + qCDebug(baseLog) << "Utils::findProgramInPath----" << proName; if (proName.isEmpty()) { - // qDebug() << "Program name is empty"; + // qCDebug(baseLog) << "Program name is empty"; return QString(); } QStringList strArg; @@ -78,8 +79,8 @@ QString Utils::findProgramInPath(const QString &proName) int Utils::executeCmdWithArtList(const QString &strCmd, const QStringList &strArg, QString &outPut, QString &error) { - qDebug() << "Utils::executeCmdWithArtList cmd: " << strCmd; - qDebug() << "Utils::executeCmdWithArtList argList: " << strArg; + qCDebug(baseLog) << "Utils::executeCmdWithArtList cmd: " << strCmd; + qCDebug(baseLog) << "Utils::executeCmdWithArtList argList: " << strArg; QProcess proc; // proc.open(QIODevice::ReadWrite); //proc.start(strcmd, strarg); @@ -109,7 +110,7 @@ int Utils::executCmd(const QString &strCmd) int Utils::executCmd(const QString &strCmd, QString *stdOut, QString *stdErr, QString &error) { - qDebug() << "Utils::executCmd" << strCmd; + qCDebug(baseLog) << "Utils::executCmd" << strCmd; QStringList args = parseCombinedArgString(strCmd); if (args.isEmpty()) { @@ -132,14 +133,14 @@ int Utils::executCmd(const QString &strCmd, QString *stdOut, QString *stdErr, QS int exitcode = proc.exitCode(); proc.close(); - qDebug() << "Utils::executCmd exitcode: " << exitcode; + qCDebug(baseLog) << "Utils::executCmd exitcode: " << exitcode; return exitcode; } int Utils::executWithInputOutputCmd(const QString &strCmdArg, const QString *inPut, QString &outPut, QString &error) { - qDebug() << "Entering Utils::executWithInputOutputCmd with command:" << strCmdArg; + qCDebug(baseLog) << "Entering Utils::executWithInputOutputCmd with command:" << strCmdArg; QProcess proc; int exitCode; @@ -152,7 +153,7 @@ int Utils::executWithInputOutputCmd(const QString &strCmdArg, const QString *inP proc.start(prog, args); if (inPut) { - qDebug() << "Writing input to process:" << *inPut; + qCDebug(baseLog) << "Writing input to process:" << *inPut; proc.waitForStarted(-1); proc.write(inPut->toLocal8Bit()); proc.closeWriteChannel(); @@ -164,14 +165,14 @@ int Utils::executWithInputOutputCmd(const QString &strCmdArg, const QString *inP exitCode = proc.exitCode(); proc.close(); - qDebug() << "Utils::executWithInputOutputCmd exitCode: " << exitCode; + qCDebug(baseLog) << "Utils::executWithInputOutputCmd exitCode: " << exitCode; return exitCode; } int Utils::executWithErrorCmd(const QString &strCmd, const QStringList &strArg, QString &outPut, QString &outPutError, QString &error) { - qDebug() << "Utils::executWithErrorCmd cmd: " << strCmd; - qDebug() << "Utils::executWithErrorCmd argList: " << strArg; + qCDebug(baseLog) << "Utils::executWithErrorCmd cmd: " << strCmd; + qCDebug(baseLog) << "Utils::executWithErrorCmd argList: " << strArg; QProcess proc; proc.setProgram(strCmd); @@ -189,46 +190,46 @@ int Utils::executWithErrorCmd(const QString &strCmd, const QStringList &strArg, QString Utils::regexpLabel(const QString &strText, const QString &strPatter) { - qDebug() << "Utils::regexpLabel strText: " << strText << "strPatter: " << strPatter; + qCDebug(baseLog) << "Utils::regexpLabel strText: " << strText << "strPatter: " << strPatter; QString strSource = strText; QString result; QRegularExpression re(strPatter, QRegularExpression::MultilineOption | QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch match = re.match(strSource); if (match.isValid() && match.hasMatch()) { - qDebug() << "Regexp match found"; + qCDebug(baseLog) << "Regexp match found"; for (int i = 0; i <= match.lastCapturedIndex(); i++) { result = match.captured(i); - qDebug() << "Captured result:" << result; + qCDebug(baseLog) << "Captured result:" << result; break; } } - qDebug() << "Utils::regexpLabel result: " << result; + qCDebug(baseLog) << "Utils::regexpLabel result: " << result; return result; } const QString Utils::getPartitionTypeString(PartitionType type) { - qDebug() << "Entering Utils::getPartitionTypeString for type:" << type; + qCDebug(baseLog) << "Entering Utils::getPartitionTypeString for type:" << type; QString strType; switch (type) { case TYPE_PRIMARY: - qDebug() << "Partition type is Primary"; + qCDebug(baseLog) << "Partition type is Primary"; strType = "Primary"; break; case TYPE_LOGICAL: - qDebug() << "Partition type is Logical"; + qCDebug(baseLog) << "Partition type is Logical"; strType = "Logical"; break; case TYPE_EXTENDED: - qDebug() << "Partition type is Extended"; + qCDebug(baseLog) << "Partition type is Extended"; strType = "Extended"; break; case TYPE_UNALLOCATED: - qDebug() << "Partition type is Unallocated"; + qCDebug(baseLog) << "Partition type is Unallocated"; strType = "Unallocated"; break; case TYPE_UNPARTITIONED: - qDebug() << "Partition type is Unpartitioned"; + qCDebug(baseLog) << "Partition type is Unpartitioned"; strType = "Unpartitioned"; break; } @@ -237,15 +238,15 @@ const QString Utils::getPartitionTypeString(PartitionType type) const QString Utils::fileSystemTypeToString(FSType type) { - qDebug() << "Entering Utils::fileSystemTypeToString for type:" << type; + qCDebug(baseLog) << "Entering Utils::fileSystemTypeToString for type:" << type; QString strFileSystemType; switch (type) { case FS_UNSUPPORTED: - qDebug() << "Filesystem type is Unsupported"; + qCDebug(baseLog) << "Filesystem type is Unsupported"; strFileSystemType = "unsupported"; break; case FS_UNALLOCATED: - qDebug() << "Filesystem type is Unallocated"; + qCDebug(baseLog) << "Filesystem type is Unallocated"; /* TO TRANSLATORS: unallocated * means that this space on the disk device is * outside any partition, so is in other words @@ -254,7 +255,7 @@ const QString Utils::fileSystemTypeToString(FSType type) strFileSystemType = "unallocated"; break; case FS_UNKNOWN: - qDebug() << "Filesystem type is Unknown"; + qCDebug(baseLog) << "Filesystem type is Unknown"; /* TO TRANSLATORS: unknown * means that this space within this partition does * not contain a file system known to GParted, and @@ -263,7 +264,7 @@ const QString Utils::fileSystemTypeToString(FSType type) strFileSystemType = "unknown"; break; case FS_UNFORMATTED: - qDebug() << "Filesystem type is Unformatted"; + qCDebug(baseLog) << "Filesystem type is Unformatted"; /* TO TRANSLATORS: unformatted * means that when the new partition is created by * GParted the space within it will not be formatted @@ -272,7 +273,7 @@ const QString Utils::fileSystemTypeToString(FSType type) strFileSystemType = "unformatted"; break; case FS_OTHER: - qDebug() << "Filesystem type is Other"; + qCDebug(baseLog) << "Filesystem type is Other"; /* TO TRANSLATORS: other * name shown in the File System Support dialog to list * actions which can be performed on other file systems @@ -281,7 +282,7 @@ const QString Utils::fileSystemTypeToString(FSType type) strFileSystemType = "other"; break; case FS_CLEARED: - qDebug() << "Filesystem type is Cleared"; + qCDebug(baseLog) << "Filesystem type is Cleared"; /* TO TRANSLATORS: cleared * means that all file system signatures in the partition * will be cleared by GParted. @@ -289,154 +290,154 @@ const QString Utils::fileSystemTypeToString(FSType type) strFileSystemType = "cleared"; break; case FS_EXTENDED: - qDebug() << "Filesystem type is Extended"; + qCDebug(baseLog) << "Filesystem type is Extended"; strFileSystemType = "extended"; break; case FS_BTRFS: - qDebug() << "Filesystem type is BTRFS"; + qCDebug(baseLog) << "Filesystem type is BTRFS"; strFileSystemType = "btrfs"; break; case FS_EXFAT: - qDebug() << "Filesystem type is exFAT"; + qCDebug(baseLog) << "Filesystem type is exFAT"; strFileSystemType = "exfat"; break; case FS_EXT2: - qDebug() << "Filesystem type is ext2"; + qCDebug(baseLog) << "Filesystem type is ext2"; strFileSystemType = "ext2"; break; case FS_EXT3: - qDebug() << "Filesystem type is ext3"; + qCDebug(baseLog) << "Filesystem type is ext3"; strFileSystemType = "ext3"; break; case FS_EXT4: - qDebug() << "Filesystem type is ext4"; + qCDebug(baseLog) << "Filesystem type is ext4"; strFileSystemType = "ext4"; break; case FS_F2FS: - qDebug() << "Filesystem type is f2fs"; + qCDebug(baseLog) << "Filesystem type is f2fs"; strFileSystemType = "f2fs"; break; case FS_FAT16: - qDebug() << "Filesystem type is FAT16"; + qCDebug(baseLog) << "Filesystem type is FAT16"; strFileSystemType = "fat16"; break; case FS_FAT32: - qDebug() << "Filesystem type is FAT32"; + qCDebug(baseLog) << "Filesystem type is FAT32"; strFileSystemType = "fat32"; break; case FS_HFS: - qDebug() << "Filesystem type is HFS"; + qCDebug(baseLog) << "Filesystem type is HFS"; strFileSystemType = "hfs"; break; case FS_HFSPLUS: - qDebug() << "Filesystem type is HFS+"; + qCDebug(baseLog) << "Filesystem type is HFS+"; strFileSystemType = "hfs+"; break; case FS_JFS: - qDebug() << "Filesystem type is JFS"; + qCDebug(baseLog) << "Filesystem type is JFS"; strFileSystemType = "jfs"; break; case FS_LINUX_SWAP: - qDebug() << "Filesystem type is Linux Swap"; + qCDebug(baseLog) << "Filesystem type is Linux Swap"; strFileSystemType = "linux-swap"; break; case FS_LUKS: - qDebug() << "Filesystem type is LUKS"; + qCDebug(baseLog) << "Filesystem type is LUKS"; strFileSystemType = "luks"; break; case FS_LVM2_PV: - qDebug() << "Filesystem type is LVM2 PV"; + qCDebug(baseLog) << "Filesystem type is LVM2 PV"; strFileSystemType = "lvm2 pv"; break; case FS_MINIX: - qDebug() << "Filesystem type is MINIX"; + qCDebug(baseLog) << "Filesystem type is MINIX"; strFileSystemType = "minix"; break; case FS_NILFS2: - qDebug() << "Filesystem type is NILFS2"; + qCDebug(baseLog) << "Filesystem type is NILFS2"; strFileSystemType = "nilfs2"; break; case FS_NTFS: - qDebug() << "Filesystem type is NTFS"; + qCDebug(baseLog) << "Filesystem type is NTFS"; strFileSystemType = "ntfs"; break; case FS_REISER4: - qDebug() << "Filesystem type is Reiser4"; + qCDebug(baseLog) << "Filesystem type is Reiser4"; strFileSystemType = "reiser4"; break; case FS_REISERFS: - qDebug() << "Filesystem type is ReiserFS"; + qCDebug(baseLog) << "Filesystem type is ReiserFS"; strFileSystemType = "reiserfs"; break; case FS_UDF: - qDebug() << "Filesystem type is UDF"; + qCDebug(baseLog) << "Filesystem type is UDF"; strFileSystemType = "udf"; break; case FS_XFS: - qDebug() << "Filesystem type is XFS"; + qCDebug(baseLog) << "Filesystem type is XFS"; strFileSystemType = "xfs"; break; case FS_APFS: - qDebug() << "Filesystem type is APFS"; + qCDebug(baseLog) << "Filesystem type is APFS"; strFileSystemType = "apfs"; break; case FS_ATARAID: - qDebug() << "Filesystem type is ATARAID"; + qCDebug(baseLog) << "Filesystem type is ATARAID"; strFileSystemType = "ataraid"; break; case FS_BITLOCKER: - qDebug() << "Filesystem type is BITLOCKER"; + qCDebug(baseLog) << "Filesystem type is BITLOCKER"; strFileSystemType = "bitlocker"; break; case FS_GRUB2_CORE_IMG: - qDebug() << "Filesystem type is GRUB2_CORE_IMG"; + qCDebug(baseLog) << "Filesystem type is GRUB2_CORE_IMG"; strFileSystemType = "grub2 core.img"; break; case FS_ISO9660: - qDebug() << "Filesystem type is ISO9660"; + qCDebug(baseLog) << "Filesystem type is ISO9660"; strFileSystemType = "iso9660"; break; case FS_LINUX_SWRAID: - qDebug() << "Filesystem type is Linux SWRAID"; + qCDebug(baseLog) << "Filesystem type is Linux SWRAID"; strFileSystemType = "linux-raid"; break; case FS_LINUX_SWSUSPEND: - qDebug() << "Filesystem type is Linux SWSUSPEND"; + qCDebug(baseLog) << "Filesystem type is Linux SWSUSPEND"; strFileSystemType = "linux-suspend"; break; case FS_REFS: - qDebug() << "Filesystem type is REFS"; + qCDebug(baseLog) << "Filesystem type is REFS"; strFileSystemType = "refs"; break; case FS_UFS: - qDebug() << "Filesystem type is UFS"; + qCDebug(baseLog) << "Filesystem type is UFS"; strFileSystemType = "ufs"; break; case FS_ZFS: - qDebug() << "Filesystem type is ZFS"; + qCDebug(baseLog) << "Filesystem type is ZFS"; strFileSystemType = "zfs"; break; case FS_USED: - qDebug() << "Filesystem type is Used"; + qCDebug(baseLog) << "Filesystem type is Used"; strFileSystemType = "used"; break; case FS_UNUSED: - qDebug() << "Filesystem type is Unused"; + qCDebug(baseLog) << "Filesystem type is Unused"; strFileSystemType = "unused"; break; default: - qDebug() << "Filesystem type is Unknown"; + qCDebug(baseLog) << "Filesystem type is Unknown"; strFileSystemType = ""; } - qDebug() << "Converted filesystem type:" << strFileSystemType; + qCDebug(baseLog) << "Converted filesystem type:" << strFileSystemType; return strFileSystemType; } FSType Utils::stringToFileSystemType(const QString &fileSystemName) { - qDebug() << "Utils::stringToFileSystemType - Converting:" << fileSystemName; - qDebug() << "Input filesystem name:" << fileSystemName; + qCDebug(baseLog) << "Utils::stringToFileSystemType - Converting:" << fileSystemName; + qCDebug(baseLog) << "Input filesystem name:" << fileSystemName; FSType type = FS_UNKNOWN; if (fileSystemName == "extended") type = FS_EXTENDED; @@ -499,13 +500,13 @@ FSType Utils::stringToFileSystemType(const QString &fileSystemName) else if (fileSystemName == "adaptec_raid_member" || fileSystemName == "ddf_raid_member" || fileSystemName == "hpt45x_raid_member" || fileSystemName == "hpt37x_raid_member" || fileSystemName == "isw_raid_member" || fileSystemName == "jmicron_raid_member" || fileSystemName == "lsi_mega_raid_member" || fileSystemName == "nvidia_raid_member" || fileSystemName == "promise_fasttrack_raid_member" || fileSystemName == "silicon_medley_raid_member" || fileSystemName == "via_raid_member") type = FS_ATARAID; - qDebug() << "Converted filesystem type:" << type; + qCDebug(baseLog) << "Converted filesystem type:" << type; return type; } int Utils::getMountedFileSystemUsage(const QString &mountpoint, Byte_Value &fileSystemSize, Byte_Value &fileSystemFree) { - qDebug() << "Utils::getMountedFileSystemUsage - Checking:" << mountpoint; + qCDebug(baseLog) << "Utils::getMountedFileSystemUsage - Checking:" << mountpoint; struct statvfs sfs; int ret; ret = statvfs(mountpoint.toStdString().c_str(), &sfs); @@ -513,10 +514,10 @@ int Utils::getMountedFileSystemUsage(const QString &mountpoint, Byte_Value &file fileSystemSize = static_cast(sfs.f_blocks) * sfs.f_bsize; fileSystemFree = static_cast(sfs.f_bavail) * sfs.f_bsize; } else { - qWarning() << "Utils::getMountedFileSystemUsage - Failed for:" << mountpoint << "Error:" << errno; + qCWarning(baseLog) << "Utils::getMountedFileSystemUsage - Failed for:" << mountpoint << "Error:" << errno; QString errorMessage("statvfs(\"%1\"):%2 "); // = "statvfs(\"" + mountpoint + "\"): " + Glib::strerror(errno) ; errorMessage = errorMessage.arg(mountpoint).arg(errno); -// qDebug() << errorMessage; +// qCDebug(baseLog) << errorMessage; } return ret; @@ -524,7 +525,7 @@ int Utils::getMountedFileSystemUsage(const QString &mountpoint, Byte_Value &file QString Utils::getFileSystemSoftWare(FSType fileSystemType) { - qDebug() << "Utils::getFileSystemSoftWare - Checking:" << fileSystemType; + qCDebug(baseLog) << "Utils::getFileSystemSoftWare - Checking:" << fileSystemType; switch (fileSystemType) { case FS_BTRFS: return "btrfs.h-progs / btrfs.h-tools"; @@ -570,13 +571,13 @@ QString Utils::getFileSystemSoftWare(FSType fileSystemType) default: return ""; } - qDebug() << "Utils::getFileSystemSoftWare - return empty"; + qCDebug(baseLog) << "Utils::getFileSystemSoftWare - return empty"; return ""; } QString Utils::formatSize(Sector sectors, Byte_Value sectorSize) { - qDebug() << "Utils::formatSize - Formatting size for sectors:" << sectors << "sectorSize:" << sectorSize; + qCDebug(baseLog) << "Utils::formatSize - Formatting size for sectors:" << sectors << "sectorSize:" << sectorSize; QString res; if ((sectors * sectorSize) < KIBIBYTE) { res = res.setNum(sectorToUnit(sectors, sectorSize, UNIT_BYTE), 'f', 2); @@ -594,13 +595,13 @@ QString Utils::formatSize(Sector sectors, Byte_Value sectorSize) res = res.setNum(sectorToUnit(sectors, sectorSize, UNIT_TIB), 'f', 2); res.append(" TiB"); } - qDebug() << "Utils::formatSize - Formatted size:" << res; + qCDebug(baseLog) << "Utils::formatSize - Formatted size:" << res; return res; } double Utils::sectorToUnit(Sector sectors, Byte_Value sectorSize, SIZE_UNIT sizeUnit) { - qDebug() << "Utils::sectorToUnit - Converting sectors:" << sectors << "sectorSize:" << sectorSize << "sizeUnit:" << sizeUnit; + qCDebug(baseLog) << "Utils::sectorToUnit - Converting sectors:" << sectors << "sectorSize:" << sectorSize << "sizeUnit:" << sizeUnit; double res = 0.0; switch (sizeUnit) { case UNIT_BYTE: @@ -621,13 +622,13 @@ double Utils::sectorToUnit(Sector sectors, Byte_Value sectorSize, SIZE_UNIT size default: res = sectors; } - qDebug() << "Utils::sectorToUnit - Converted value:" << res; + qCDebug(baseLog) << "Utils::sectorToUnit - Converted value:" << res; return res; } int Utils::getMaxPartitionNameLength(QString &tableType) { - qDebug() << "Utils::getMaxPartitionNameLength - Checking tableType:" << tableType; + qCDebug(baseLog) << "Utils::getMaxPartitionNameLength - Checking tableType:" << tableType; if (tableType == "amiga") return 0; // Disabled else if (tableType == "dvh") @@ -639,25 +640,25 @@ int Utils::getMaxPartitionNameLength(QString &tableType) else if (tableType == "pc98") return 0; // Disabled - qDebug() << "Utils::getMaxPartitionNameLength - Returning 0"; + qCDebug(baseLog) << "Utils::getMaxPartitionNameLength - Returning 0"; return 0; } Byte_Value Utils::floorSize(Byte_Value value, Byte_Value roundingSize) { - // qInfo() << "Utils::floorSize - value:" << value << "roundingSize:" << roundingSize; + // qCInfo(baseLog) << "Utils::floorSize - value:" << value << "roundingSize:" << roundingSize; return value / roundingSize * roundingSize; } Byte_Value Utils::ceilSize(Byte_Value value, Byte_Value roundingSize) { - // qInfo() << "Utils::ceilSize - value:" << value << "roundingSize:" << roundingSize; + // qCInfo(baseLog) << "Utils::ceilSize - value:" << value << "roundingSize:" << roundingSize; return (value + roundingSize - 1LL) / roundingSize * roundingSize; } QString Utils::createUuid() { - qInfo() << "Utils::createUuid - Creating UUID"; + qCInfo(baseLog) << "Utils::createUuid - Creating UUID"; QUuid uuid; return uuid.createUuid().toString(QUuid::WithoutBraces); } @@ -665,7 +666,7 @@ QString Utils::createUuid() QString Utils::LVMFormatSize(long long lvmSize) { - qInfo() << "Utils::LVMFormatSize - Formatting size for lvmSize:" << lvmSize; + qCInfo(baseLog) << "Utils::LVMFormatSize - Formatting size for lvmSize:" << lvmSize; QString res; if (lvmSize < KIBIBYTE) { res = res.setNum(LVMSizeToUnit(lvmSize, UNIT_BYTE), 'f', 2); @@ -683,13 +684,13 @@ QString Utils::LVMFormatSize(long long lvmSize) res = res.setNum(LVMSizeToUnit(lvmSize, UNIT_TIB), 'f', 2); res.append(" TiB"); } - qInfo() << "Utils::LVMFormatSize - Formatted size:" << res; + qCInfo(baseLog) << "Utils::LVMFormatSize - Formatted size:" << res; return res; } double Utils::LVMSizeToUnit(long long lvmSize, SIZE_UNIT sizeUnit) { - qInfo() << "Utils::LVMSizeToUnit - Converting lvmSize:" << lvmSize << "sizeUnit:" << sizeUnit; + qCInfo(baseLog) << "Utils::LVMSizeToUnit - Converting lvmSize:" << lvmSize << "sizeUnit:" << sizeUnit; double res = 0.0; switch (sizeUnit) { case UNIT_BYTE: @@ -710,13 +711,13 @@ double Utils::LVMSizeToUnit(long long lvmSize, SIZE_UNIT sizeUnit) default: res = lvmSize; } - qInfo() << "Utils::LVMSizeToUnit - Converted value:" << res; + qCInfo(baseLog) << "Utils::LVMSizeToUnit - Converted value:" << res; return res; } bool Utils::adjudicationPVDelete(LVMInfo lvmInfo, const set &pvStrList, bool &bigDataMove, QStringList &realMovePvList) { - qDebug() << "Entering Utils::adjudicationPVDelete"; + qCDebug(baseLog) << "Entering Utils::adjudicationPVDelete"; bigDataMove = false; //获取所有存在于vg中 待删除的pv QMap>t_map; @@ -731,7 +732,7 @@ bool Utils::adjudicationPVDelete(LVMInfo lvmInfo, const set &pvStrList, } if (!lvmInfo.pvOfVg(pv)) { //vg不存在或pv不在vg中 说明数据有错误 - qWarning() << "pv not join vg"; + qCWarning(baseLog) << "pv not join vg"; return false; } t_map[pv.m_vgName].push_back(pv.m_pvPath); @@ -754,23 +755,23 @@ bool Utils::adjudicationPVDelete(LVMInfo lvmInfo, const set &pvStrList, } } if (vgInfo.m_peUnused - unusedPE < remvoePE) { //判断是否允许删除 - qWarning() << "pv used pe more than vg unused pe"; + qCWarning(baseLog) << "pv used pe more than vg unused pe"; return false; } if (!bigDataMove) { //判断是否存在大量数据需要移动 - qInfo() << "Utils::adjudicationPVDelete - Checking if large data move is needed"; + qCInfo(baseLog) << "Utils::adjudicationPVDelete - Checking if large data move is needed"; remvoeAllSize += (remvoePE * vgInfo.m_PESize); bigDataMove = ((remvoeAllSize / GIBIBYTE) >= 1); } } - qInfo() << "Utils::adjudicationPVDelete return true"; + qCInfo(baseLog) << "Utils::adjudicationPVDelete return true"; return true; } QString Utils::getCipherStr(CRYPT_CIPHER cipher) { - qDebug() << "Entering Utils::getCipherStr for cipher:" << cipher; + qCDebug(baseLog) << "Entering Utils::getCipherStr for cipher:" << cipher; switch (cipher) { case CRYPT_CIPHER::NOT_CRYPT: return QString("not_crypt"); @@ -785,7 +786,7 @@ QString Utils::getCipherStr(CRYPT_CIPHER cipher) CRYPT_CIPHER Utils::getCipher(QString cipher) { - qDebug() << "Entering Utils::getCipher for cipher:" << cipher; + qCDebug(baseLog) << "Entering Utils::getCipher for cipher:" << cipher; if (cipher.contains("not_crypt")) { return CRYPT_CIPHER::NOT_CRYPT; } else if (cipher.contains("aes-xts-plain64")) { @@ -800,13 +801,13 @@ CRYPT_CIPHER Utils::getCipher(QString cipher) bool Utils::kernelSupportFS(const QString &fsType) { - qDebug() << "Utils::kernelSupportFS - Checking support for:" << fsType; + qCDebug(baseLog) << "Utils::kernelSupportFS - Checking support for:" << fsType; bool supported = false; QFile file("/proc/filesystems"); if (file.open(QIODevice::ReadOnly)) { QString info = file.readAll(); if (info.contains(fsType)) { - qDebug() << "Utils::kernelSupportFS - Supported:" << fsType; + qCDebug(baseLog) << "Utils::kernelSupportFS - Supported:" << fsType; supported = true; } file.close(); @@ -816,11 +817,11 @@ bool Utils::kernelSupportFS(const QString &fsType) QString Utils::mkTempDir(const QString &infix) { - qDebug() << "Utils::mkTempDir - Creating temp dir with infix:" << infix; + qCDebug(baseLog) << "Utils::mkTempDir - Creating temp dir with infix:" << infix; // 路径遍历检查:拒绝包含 ".." 的 infix if (infix.contains("..")) { - qWarning() << "Utils::mkTempDir - Invalid infix contains path traversal:" << infix; + qCWarning(baseLog) << "Utils::mkTempDir - Invalid infix contains path traversal:" << infix; return QString(); } @@ -833,32 +834,32 @@ QString Utils::mkTempDir(const QString &infix) dirTemplate += "XXXXXX" ; QDir dir(dirTemplate); if (!dir.exists() && dir.mkpath(dirTemplate)) { - qDebug() << "Utils::mkTempDir - Created temp dir:" << dirTemplate; + qCDebug(baseLog) << "Utils::mkTempDir - Created temp dir:" << dirTemplate; return dirTemplate; } - qDebug() << "Utils::mkTempDir - Using existing temp dir:" << dirTemplate; + qCDebug(baseLog) << "Utils::mkTempDir - Using existing temp dir:" << dirTemplate; return dirTemplate; } void Utils::rmTempDir(QString &dirName) { - qDebug() << "Utils::rmTempDir - Removing temp dir:" << dirName; + qCDebug(baseLog) << "Utils::rmTempDir - Removing temp dir:" << dirName; QDir dir(dirName); if (dir.exists()) { dir.remove(dirName); - qDebug() << "Utils::rmTempDir - Removed temp dir:" << dirName; + qCDebug(baseLog) << "Utils::rmTempDir - Removed temp dir:" << dirName; } else { - qDebug() << "Utils::rmTempDir - Temp dir does not exist:" << dirName; + qCDebug(baseLog) << "Utils::rmTempDir - Temp dir does not exist:" << dirName; } } QString Utils::readContent(const QString &filename) { - qDebug() << "Utils::readContent - Reading file:" << filename; + qCDebug(baseLog) << "Utils::readContent - Reading file:" << filename; QString ret; QFile file(filename); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Utils::readContent - Successfully read:" << filename; + qCDebug(baseLog) << "Utils::readContent - Successfully read:" << filename; ret = file.readAll(); file.close(); }