From 4bf5bb467f6c029da7871f8bd2a78410a5f03e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 3 Dec 2017 12:37:21 +0000 Subject: [PATCH] Fix conversion to/from QString/QByteArray BUG: 384321 --- src/core/partition.cpp | 2 +- src/core/smartstatus.cpp | 6 +++--- src/fs/filesystem.cpp | 4 ++-- src/fs/luks.cpp | 8 ++++---- src/plugins/libparted/libpartedbackend.cpp | 18 +++++++++--------- src/plugins/libparted/libparteddevice.cpp | 6 +++--- .../libparted/libpartedpartitiontable.cpp | 14 +++++++------- src/util/externalcommand.cpp | 2 +- src/util/htmlreport.cpp | 2 +- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/core/partition.cpp b/src/core/partition.cpp index 405f583..5b7c3a0 100644 --- a/src/core/partition.cpp +++ b/src/core/partition.cpp @@ -335,7 +335,7 @@ bool Partition::unmount(Report& report) const QString canonicalDeviceNode = QFileInfo(deviceNode()).canonicalFilePath(); const QList mountedVolumes = QStorageInfo::mountedVolumes(); for (const QStorageInfo &storage : mountedVolumes) { - if (QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() == canonicalDeviceNode ) { + if (QFileInfo(QString::fromLocal8Bit(storage.device())).canonicalFilePath() == canonicalDeviceNode ) { success = false; break; } diff --git a/src/core/smartstatus.cpp b/src/core/smartstatus.cpp index 2a7c280..8b1cb91 100644 --- a/src/core/smartstatus.cpp +++ b/src/core/smartstatus.cpp @@ -77,9 +77,9 @@ void SmartStatus::update() if (sk_disk_identify_parse(skDisk, &skIdentify) < 0) qDebug() << "getting identify data failed for " << devicePath() << ": " << strerror(errno); else { - setModelName(QString::fromUtf8(skIdentify->model)); - setFirmware(QString::fromUtf8(skIdentify->firmware)); - setSerial(QString::fromUtf8(skIdentify->serial)); + setModelName(QString::fromLocal8Bit(skIdentify->model)); + setFirmware(QString::fromLocal8Bit(skIdentify->firmware)); + setSerial(QString::fromLocal8Bit(skIdentify->serial)); } const SkSmartParsedData* skParsed; diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp index bbc6ae8..fa2413c 100644 --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -110,7 +110,7 @@ static QString readBlkIdValue(const QString& deviceNode, const QString& tag) char* label = nullptr; if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr && (label = blkid_get_tag_value(cache, tag.toLocal8Bit().constData(), deviceNode.toLocal8Bit().constData()))) { - rval = QString::fromUtf8(label); + rval = QString::fromLocal8Bit(label); free(label); } @@ -138,7 +138,7 @@ QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPat QString partitionCanonicalPath = partitionPathFileInfo.canonicalFilePath(); const QList mountedVolumes = QStorageInfo::mountedVolumes(); for (const QStorageInfo &storage : mountedVolumes) { - if (partitionCanonicalPath == QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() ) { + if (partitionCanonicalPath == QFileInfo(QString::fromLocal8Bit(storage.device())).canonicalFilePath() ) { mountPoints.append(storage.rootPath()); } } diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index a80cf01..86dbaea 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -128,7 +128,7 @@ bool luks::create(Report& report, const QString& deviceNode) QStringLiteral("luksFormat"), deviceNode }); if (!( createCmd.start(-1) && - createCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 && + createCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 && createCmd.waitFor() && createCmd.exitCode() == 0)) { return false; @@ -139,7 +139,7 @@ bool luks::create(Report& report, const QString& deviceNode) deviceNode, suggestedMapperName(deviceNode) }); - if (!( openCmd.start(-1) && openCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 && openCmd.waitFor())) + if (!( openCmd.start(-1) && openCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 && openCmd.waitFor())) return false; scan(deviceNode); @@ -262,7 +262,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode) suggestedMapperName(deviceNode) }); if (!( openCmd.start(-1) && - openCmd.write(passphrase.toUtf8() + '\n') == passphrase.toUtf8().length() + 1 && + openCmd.write(passphrase.toLocal8Bit() + '\n') == passphrase.toLocal8Bit().length() + 1 && openCmd.waitFor() && openCmd.exitCode() == 0) ) return false; @@ -572,7 +572,7 @@ void luks::getMapperName(const QString& deviceNode) m_MapperName = QString(); if (cmd.run(-1) && cmd.exitCode() == 0) { - const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toUtf8()); + const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toLocal8Bit()); QJsonObject jsonObject = jsonDocument.object(); const QJsonArray jsonArray = jsonObject[QLatin1String("blockdevices")].toArray(); for (const auto &deviceLine : jsonArray) { diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 2081fe9..8a06bb4 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -107,7 +107,7 @@ typedef struct _GPTDiskData GPTDiskData; */ static qint64 firstUsableSector(const Device& d) { - PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData()); + PedDevice* pedDevice = ped_device_get(d.deviceNode().toLocal8Bit().constData()); PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr; qint64 rval = 0; @@ -135,7 +135,7 @@ static qint64 firstUsableSector(const Device& d) */ static qint64 lastUsableSector(const Device& d) { - PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData()); + PedDevice* pedDevice = ped_device_get(d.deviceNode().toLocal8Bit().constData()); PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr; qint64 rval = 0; @@ -305,7 +305,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) FileSystem::Type type = FileSystem::Unknown; char* pedPath = ped_partition_get_path(pedPartition); - const QString partitionNode = pedPath ? QString::fromUtf8(pedPath) : QString(); + const QString partitionNode = pedPath ? QString::fromLocal8Bit(pedPath) : QString(); free(pedPath); type = detectFileSystem(partitionNode); @@ -393,14 +393,14 @@ DiskDevice* LibPartedBackend::scanDevice(const QString& deviceNode) return nullptr; } - Log(Log::information) << xi18nc("@info:status", "Device found: %1", QString::fromUtf8(pedDevice->model)); + Log(Log::information) << xi18nc("@info:status", "Device found: %1", QString::fromLocal8Bit(pedDevice->model)); - DiskDevice* d = new DiskDevice(QString::fromUtf8(pedDevice->model), QString::fromUtf8(pedDevice->path), pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size); + DiskDevice* d = new DiskDevice(QString::fromLocal8Bit(pedDevice->model), QString::fromLocal8Bit(pedDevice->path), pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size); PedDisk* pedDisk = ped_disk_new(pedDevice); if (pedDisk) { - const PartitionTable::TableType type = PartitionTable::nameToTableType(QString::fromUtf8(pedDisk->type->name)); + const PartitionTable::TableType type = PartitionTable::nameToTableType(QString::fromLocal8Bit(pedDisk->type->name)); CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(type, firstUsableSector(*d), lastUsableSector(*d))); CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), ped_disk_get_max_primary_partition_count(pedDisk)); @@ -426,7 +426,7 @@ QList LibPartedBackend::scanDevices(bool excludeReadOnly) QStringLiteral("type,name") }); if (cmd.run(-1) && cmd.exitCode() == 0) { - const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toUtf8()); + const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toLocal8Bit()); QJsonObject jsonObject = jsonDocument.object(); const QJsonArray jsonArray = jsonObject[QLatin1String("blockdevices")].toArray(); for (const auto &deviceLine : jsonArray) { @@ -479,7 +479,7 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath partitionPath.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr) { char *string = blkid_get_tag_value(cache, "TYPE", partitionPath.toLocal8Bit().constData()); - QString s = QString::fromUtf8(string); + QString s = QString::fromLocal8Bit(string); free(string); if (s == QStringLiteral("ext2")) rval = FileSystem::Ext2; @@ -497,7 +497,7 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath else if (s == QStringLiteral("vfat")) { // libblkid uses SEC_TYPE to distinguish between FAT16 and FAT32 string = blkid_get_tag_value(cache, "SEC_TYPE", partitionPath.toLocal8Bit().constData()); - QString st = QString::fromUtf8(string); + QString st = QString::fromLocal8Bit(string); free(string); if (st == QStringLiteral("msdos")) rval = FileSystem::Fat16; diff --git a/src/plugins/libparted/libparteddevice.cpp b/src/plugins/libparted/libparteddevice.cpp index 4a3bc30..6354b58 100644 --- a/src/plugins/libparted/libparteddevice.cpp +++ b/src/plugins/libparted/libparteddevice.cpp @@ -45,7 +45,7 @@ bool LibPartedDevice::open() if (pedDevice()) return false; - m_PedDevice = ped_device_get(deviceNode().toLatin1().constData()); + m_PedDevice = ped_device_get(deviceNode().toLocal8Bit().constData()); return m_PedDevice != nullptr; } @@ -87,14 +87,14 @@ CoreBackendPartitionTable* LibPartedDevice::openPartitionTable() bool LibPartedDevice::createPartitionTable(Report& report, const PartitionTable& ptable) { - PedDiskType* pedDiskType = ped_disk_type_get(ptable.typeName().toLatin1().constData()); + PedDiskType* pedDiskType = ped_disk_type_get(ptable.typeName().toLocal8Bit().constData()); if (pedDiskType == nullptr) { report.line() << xi18nc("@info:progress", "Creating partition table failed: Could not retrieve partition table type \"%1\" for %2.", ptable.typeName(), deviceNode()); return false; } - PedDevice* dev = ped_device_get(deviceNode().toLatin1().constData()); + PedDevice* dev = ped_device_get(deviceNode().toLocal8Bit().constData()); if (dev == nullptr) { report.line() << xi18nc("@info:progress", "Creating partition table failed: Could not open backend device %1.", deviceNode()); diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index 34cbb10..d4fd7e2 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -125,7 +125,7 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t) { for (quint32 i = 0; i < sizeof(mapFileSystemTypeToLibPartedName) / sizeof(mapFileSystemTypeToLibPartedName[0]); i++) if (mapFileSystemTypeToLibPartedName[i].type == t) - return ped_file_system_type_get(mapFileSystemTypeToLibPartedName[i].name.toLatin1().constData()); + return ped_file_system_type_get(mapFileSystemTypeToLibPartedName[i].name.toLocal8Bit().constData()); // if we didn't find anything, go with ext2 as a safe fallback return ped_file_system_type_get("ext2"); @@ -133,7 +133,7 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t) QString LibPartedPartitionTable::createPartition(Report& report, const Partition& partition) { - Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); + Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path)); QString rval = QString(); @@ -177,11 +177,11 @@ QString LibPartedPartitionTable::createPartition(Report& report, const Partition if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint)) { char *pedPath = ped_partition_get_path(pedPartition); - rval = QString::fromUtf8(pedPath); + rval = QString::fromLocal8Bit(pedPath); free(pedPath); } else { - report.line() << xi18nc("@info:progress", "Failed to add partition %1 to device %2.", partition.deviceNode(), QString::fromUtf8(pedDisk()->dev->path)); + report.line() << xi18nc("@info:progress", "Failed to add partition %1 to device %2.", partition.deviceNode(), QString::fromLocal8Bit(pedDisk()->dev->path)); report.line() << LibPartedBackend::lastPartedExceptionMessage(); } @@ -192,7 +192,7 @@ QString LibPartedPartitionTable::createPartition(Report& report, const Partition bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& partition) { - Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); + Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path)); bool rval = false; @@ -213,7 +213,7 @@ bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& p bool LibPartedPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) { - Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path)); + Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path)); bool rval = false; @@ -317,7 +317,7 @@ FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& repor char* pedPath = ped_partition_get_path(pedPartition); FileSystem::Type type = FileSystem::Unknown; if (pedPartition && pedPath) - type = CoreBackendManager::self()->backend()->detectFileSystem(QString::fromUtf8(pedPath)); + type = CoreBackendManager::self()->backend()->detectFileSystem(QString::fromLocal8Bit(pedPath)); else report.line() << xi18nc("@info:progress", "Could not determine file system of partition at sector %1 on device %2.", sector, device.deviceNode()); free(pedPath); diff --git a/src/util/externalcommand.cpp b/src/util/externalcommand.cpp index fd6f4e9..2bbc8fc 100644 --- a/src/util/externalcommand.cpp +++ b/src/util/externalcommand.cpp @@ -59,7 +59,7 @@ ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStri void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode) { - setEnvironment(QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("PATH=") + QString::fromUtf8(getenv("PATH")) << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1")); + setEnvironment(QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("PATH=") + QString::fromLocal8Bit(getenv("PATH")) << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1")); setProcessChannelMode(processChannelMode); connect(this, qOverload(&QProcess::finished), this, &ExternalCommand::onFinished); diff --git a/src/util/htmlreport.cpp b/src/util/htmlreport.cpp index e0b00d6..0db2e3e 100644 --- a/src/util/htmlreport.cpp +++ b/src/util/htmlreport.cpp @@ -71,7 +71,7 @@ QString HtmlReport::header() struct utsname info; uname(&info); - const QString unameString = QString::fromUtf8(info.sysname) + QStringLiteral(" ") + QString::fromUtf8(info.nodename) + QStringLiteral(" ") + QString::fromUtf8(info.release) + QStringLiteral(" ") + QString::fromUtf8(info.version) + QStringLiteral(" ") + QString::fromUtf8(info.machine); + const QString unameString = QString::fromLocal8Bit(info.sysname) + QStringLiteral(" ") + QString::fromLocal8Bit(info.nodename) + QStringLiteral(" ") + QString::fromLocal8Bit(info.release) + QStringLiteral(" ") + QString::fromLocal8Bit(info.version) + QStringLiteral(" ") + QString::fromLocal8Bit(info.machine); s << "\n" << tableLine(i18n("Date:"), QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat))