Skip to content

Commit

Permalink
fix: cannot correctly recoganize fstab partitions
Browse files Browse the repository at this point in the history
- remove the isFstabItem function;
- add Block::Configuration filed in device properties;
- initialize param.initOnly with true if
Block::Configuration.contains("fstab");

Log: fix partition encrypt issue.

Bug: https://pms.uniontech.com/bug-view-292155.html
  • Loading branch information
itsXuSt authored and deepin-bot[bot] committed Dec 5, 2024
1 parent fc16275 commit 86d10f8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
16 changes: 16 additions & 0 deletions src/dfm-base/base/device/private/devicehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <QStandardPaths>
#include <QProcess>
#include <QTextStream>
#include <QJsonDocument>
#include <QJsonObject>

#include <dfm-mount/dmount.h>
#include <dfm-burn/dburn_global.h>
Expand Down Expand Up @@ -121,6 +123,20 @@ QVariantMap DeviceHelper::loadBlockInfo(const BlockDevAutoPtr &dev)
datas[kDriveModel] = getNullStrIfNotValid(Property::kDriveModel);
datas[kPreferredDevice] = getNullStrIfNotValid(Property::kBlockPreferredDevice);

auto config = dev->getProperty(Property::kBlockConfiguration).toMap();
if (!config.isEmpty()) {
QJsonObject jsonRootObj;
QMapIterator<QString, QVariant> iter(config);
while (iter.hasNext()) {
iter.next();
auto key = iter.key();
QVariantMap value = iter.value().toMap();
jsonRootObj.insert(key, QJsonObject::fromVariantMap(value));
}
QJsonDocument doc(jsonRootObj);
datas[kConfiguration] = QString(doc.toJson(QJsonDocument::Compact));
}

datas[kUDisks2Size] = dev->sizeTotal();
auto mpt = dev->mountPoint();
if (!mpt.isEmpty() && !dev->optical()) {
Expand Down
1 change: 1 addition & 0 deletions src/dfm-base/dbusservice/global_server_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ inline constexpr char kConnectionBus[] { "ConnectionBus" };
inline constexpr char kUDisks2Size[] { "UDisks2Size" };
inline constexpr char kDriveModel[] { "DriveModel" };
inline constexpr char kPreferredDevice[] { "PreferredDevice" };
inline constexpr char kConfiguration[] { "Configuration" };
} // namespace DeviceProperty

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <QDBusInterface>
#include <QDBusReply>
#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>

#include <ddialog.h>
#include <dconfig.h>
Expand Down Expand Up @@ -105,9 +108,20 @@ bool DiskEncryptMenuScene::initialize(const QVariantHash &params)
return false;
}

param.initOnly = false;
auto configJson = selectedItemInfo.value("Configuration", "").toString();
if (!configJson.isEmpty()) {
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson(configJson.toLocal8Bit(), &err);
if (err.error != QJsonParseError::NoError) {
qWarning() << "device configuration not valid!" << device << configJson;
return false;
}
auto obj = doc.object();
param.initOnly = obj.contains("fstab");
}
param.devID = selectedItemInfo.value("Id").toString();
param.devDesc = device;
param.initOnly = fstab_utils::isFstabItem(devMpt);
param.mountPoint = devMpt;
param.uuid = selectedItemInfo.value("IdUUID", "").toString();
param.deviceDisplayName = info->displayOf(dfmbase::FileInfo::kFileDisplayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,6 @@ QString config_utils::cipherType()
return cipher;
}

bool fstab_utils::isFstabItem(const QString &mpt)
{
if (mpt.isEmpty())
return false;

bool fstabed { false };
struct fstab *fs;
setfsent();
while ((fs = getfsent()) != nullptr) {
QString path = fs->fs_file;
if (mpt == path) {
fstabed = true;
break;
}
}
endfsent();
return fstabed;
}

int tpm_utils::checkTPM()
{
return dpfSlotChannel->push("dfmplugin_encrypt_manager", "slot_TPMIsAvailablePro").toInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ namespace recovery_key_utils {
QString formatRecoveryKey(const QString &raw);
}

namespace fstab_utils {
bool isFstabItem(const QString &mpt);
} // namespace fstab_utils

namespace device_utils {
int encKeyType(const QString &dev);
void cacheToken(const QString &device, const QVariantMap &token);
Expand Down

0 comments on commit 86d10f8

Please sign in to comment.