Skip to content

Commit

Permalink
feat: compatibility mode support debconf and verify.
Browse files Browse the repository at this point in the history
Adapt compatibility mode:
Support DebConf templates config;
Support hierarchical verify.

Log: Compatibility mode support DebConf and verify.
Influence: compatible
  • Loading branch information
rb-union committed Oct 30, 2024
1 parent 74843aa commit 4582719
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
19 changes: 19 additions & 0 deletions src/deb-installer/compatible/compatible_process_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ bool CompatibleProcessController::install(const Deb::DebPackage::Ptr &package)
m_outputList.clear();
m_currentPackage = package;

// reset state
m_currentPackage->setError(Pkg::NoError, {});

// For historical reasons, the first argument in programArguments is the
// name of the program to execute, so create a list consisting of all
// but the first argument to pass to setProgram()
Expand Down Expand Up @@ -94,6 +97,9 @@ bool CompatibleProcessController::uninstall(const Deb::DebPackage::Ptr &package)
m_outputList.clear();
m_currentPackage = package;

// reset state
m_currentPackage->setError(Pkg::NoError, {});

// For historical reasons, the first argument in programArguments is the
// name of the program to execute, so create a list consisting of all
// but the first argument to pass to setProgram()
Expand All @@ -115,6 +121,19 @@ bool CompatibleProcessController::uninstall(const Deb::DebPackage::Ptr &package)
return true;
}

bool CompatibleProcessController::containTemplates() const
{
return m_currentPackage && m_currentPackage->containsTemplates();
}

void CompatibleProcessController::writeConfigData(const QString &configData)
{
if (m_process) {
m_process->pty()->write(configData.toUtf8());
m_process->pty()->write("\n");
}
}

bool CompatibleProcessController::ensureProcess()
{
if (!m_process) {
Expand Down
3 changes: 3 additions & 0 deletions src/deb-installer/compatible/compatible_process_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class CompatibleProcessController : public QObject
[[nodiscard]] bool install(const Deb::DebPackage::Ptr &package);
[[nodiscard]] bool uninstall(const Deb::DebPackage::Ptr &package);

[[nodiscard]] bool containTemplates() const;
void writeConfigData(const QString &configData);

Q_SIGNAL void processStart();
Q_SIGNAL void processFinished(bool success);
Q_SIGNAL void processOutput(const QString &output);
Expand Down
28 changes: 22 additions & 6 deletions src/deb-installer/model/deblistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,11 @@ void DebListModel::slotConfigReadOutput(const char *buffer, int length, bool isC

void DebListModel::slotConfigInputWrite(const QString &str)
{
if (supportCompatible() && m_compProcessor && m_compProcessor->isRunning()) {
m_compProcessor->writeConfigData(str);
return;
}

m_procInstallConfig->pty()->write(str.toUtf8()); // 将用户输入的配置项写入到配置安装进程中。
m_procInstallConfig->pty()->write("\n"); // 写入换行,配置生效
}
Expand Down Expand Up @@ -1686,18 +1691,29 @@ void DebListModel::ensureCompatibleProcessor()
if (!m_compProcessor) {
m_compProcessor.reset(new Compatible::CompatibleProcessController);

connect(m_compProcessor.data(),
&Compatible::CompatibleProcessController::processOutput,
this,
&DebListModel::signalAppendOutputInfo);
connect(
m_compProcessor.data(), &Compatible::CompatibleProcessController::processOutput, this, [this](const QString &output) {
Q_EMIT signalAppendOutputInfo(output);
if (m_compProcessor->containTemplates()) {
configWindow->appendTextEdit(output);
configWindow->show();
}
});

connect(m_compProcessor.data(), &Compatible::CompatibleProcessController::progressChanged, this, [this](float progress) {
const int progressValue =
static_cast<int>((100. / m_packagesManager->m_preparedPackages.size()) * (m_operatingIndex + progress / 100.));
Q_EMIT signalWholeProgressChanged(progressValue);

Q_EMIT signalCurrentPacakgeProgressChanged(progress);
Q_EMIT signalCurrentPacakgeProgressChanged(static_cast<int>(progress));
});

connect(m_compProcessor.data(), &Compatible::CompatibleProcessController::processFinished, this, [this](bool success) {
if (configWindow->isVisible()) {
configWindow->hide();
configWindow->clearTexts();
}

if (success) {
refreshOperatingPackageStatus(Pkg::Success);
} else {
Expand All @@ -1712,7 +1728,7 @@ void DebListModel::ensureCompatibleProcessor()

if (Pkg::ConfigAuthCancel == pkgPtr->errorCode()) {
// notify UI reset, cancel current flow
setWorkerStatus(WorkerPrepare);
m_workerStatus = WorkerPrepare;
Q_EMIT signalAuthCancel();
refreshOperatingPackageStatus(Pkg::Failed);
return;
Expand Down
1 change: 0 additions & 1 deletion src/deb-installer/model/proxy_package_list_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ bool ProxyPackageListModel::nextModelInstall()
if (m_procModelIndex >= m_packageModels.count()) {
setWorkerStatus(WorkerFinished);
Q_EMIT signalWholeProgressChanged(100);
setWorkerStatus(WorkerFinished);
return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/deb-installer/utils/deb_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ PackageDependsStatus &DebPackage::dependsStatus()

bool DebPackage::containsTemplates()
{
return Utils::checkPackageContainsDebConf(m_debFilePtr->filePath());
if (UnknownTemplates == m_templatesState) {
m_templatesState = Utils::checkPackageContainsDebConf(m_debFilePtr->filePath()) ? ContainTemplates : NoTemplates;
}

return m_templatesState == ContainTemplates;
}

void DebPackage::setError(int code, const QString &string)
Expand Down
7 changes: 7 additions & 0 deletions src/deb-installer/utils/deb_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class DebPackage

QSharedPointer<Compatible::CompPkgInfo> m_compInfoPtr;

enum TemplatesState {
UnknownTemplates,
ContainTemplates,
NoTemplates,
};
TemplatesState m_templatesState{UnknownTemplates};

Q_DISABLE_COPY(DebPackage)
};

Expand Down
5 changes: 4 additions & 1 deletion src/deb-installer/view/pages/singleinstallpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void SingleInstallPage::initConnections()
connect(m_confirmButton, &DPushButton::clicked, this, [this]() {
QModelIndex index = m_packagesModel->index(0);
const int dependsStat = index.data(DebListModel::PackageDependsStatusRole).toInt();
if (Pkg::CompatibleNotInstalled == dependsStat) {
if (Finished != m_operate && Pkg::CompatibleNotInstalled == dependsStat) {
// requset install package to compatible.
m_targetRootfsOsName = m_compatibleBox->currentText();
const QString targetRootfs = m_compatibleBox->currentData().toString();
Expand Down Expand Up @@ -882,6 +882,9 @@ void SingleInstallPage::slotWorkerFinished()
}
if (!m_upDown)
m_infoControlButton->setShrinkTips(tr("Collapse"));

// mark down
m_operate = Finished;
}

void SingleInstallPage::slotWorkerProgressChanged(const int progress)
Expand Down
9 changes: 5 additions & 4 deletions src/deb-installer/view/pages/singleinstallpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ public slots:

private:
/**
* @brief The Operate enum 当前进行的操作
* @brief The current operate
*/
enum Operate {
Unknown,
Install, // 安装
Uninstall, // 卸载
Reinstall // 重新安装
Install,
Uninstall,
Reinstall,
Finished, // install/uninstall finished
};

private:
Expand Down

0 comments on commit 4582719

Please sign in to comment.