From 1704ad597795d3142627e2fc3119fae3dab621a8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Feb 2021 19:18:19 +0100 Subject: [PATCH] [partition] Add a job to handle automount behavior - while here, nudge CalamaresUtils automount API a little, since it doesn't really need an rvalue-ref. --- src/libcalamares/partition/AutoMount.cpp | 2 +- src/libcalamares/partition/AutoMount.h | 2 +- src/modules/partition/CMakeLists.txt | 1 + .../partition/jobs/AutoMountManagementJob.cpp | 39 +++++++++++++++++ .../partition/jobs/AutoMountManagementJob.h | 42 +++++++++++++++++++ 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/modules/partition/jobs/AutoMountManagementJob.cpp create mode 100644 src/modules/partition/jobs/AutoMountManagementJob.h diff --git a/src/libcalamares/partition/AutoMount.cpp b/src/libcalamares/partition/AutoMount.cpp index 0fc253067..0edc89bf4 100644 --- a/src/libcalamares/partition/AutoMount.cpp +++ b/src/libcalamares/partition/AutoMount.cpp @@ -79,7 +79,7 @@ automountDisable( bool disable ) void -automountRestore( std::shared_ptr< AutoMountInfo >&& t ) +automountRestore( const std::shared_ptr< AutoMountInfo >& t ) { QDBusConnection dbus = QDBusConnection::sessionBus(); enableSolidAutoMount( dbus, t->wasSolidModuleAutoLoaded ); diff --git a/src/libcalamares/partition/AutoMount.h b/src/libcalamares/partition/AutoMount.h index a9a88e320..c792eeb99 100644 --- a/src/libcalamares/partition/AutoMount.h +++ b/src/libcalamares/partition/AutoMount.h @@ -43,7 +43,7 @@ DLLEXPORT std::shared_ptr< AutoMountInfo > automountDisable( bool disable = true * Pass the value returned from automountDisable() to restore the * previous settings. */ -DLLEXPORT void automountRestore( std::shared_ptr< AutoMountInfo >&& t ); +DLLEXPORT void automountRestore( const std::shared_ptr< AutoMountInfo >& t ); } // namespace Partition } // namespace CalamaresUtils diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index b623309c5..ac47714ce 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -79,6 +79,7 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND gui/ScanningDialog.cpp gui/ReplaceWidget.cpp gui/VolumeGroupBaseDialog.cpp + jobs/AutoMountManagementJob.cpp jobs/ClearMountsJob.cpp jobs/ClearTempMountsJob.cpp jobs/CreatePartitionJob.cpp diff --git a/src/modules/partition/jobs/AutoMountManagementJob.cpp b/src/modules/partition/jobs/AutoMountManagementJob.cpp new file mode 100644 index 000000000..2ea23666c --- /dev/null +++ b/src/modules/partition/jobs/AutoMountManagementJob.cpp @@ -0,0 +1,39 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "AutoMountManagementJob.h" + +#include "utils/Logger.h" + +AutoMountManagementJob::AutoMountManagementJob( bool disable ) + : m_disable( disable ) +{ +} + +QString +AutoMountManagementJob::prettyName() const +{ + return tr( "Manage auto-mount settings" ); +} + +Calamares::JobResult +AutoMountManagementJob::exec() +{ + cDebug() << "this" << Logger::Pointer( this ) << "value" << Logger::Pointer( m_stored.get() ); + if ( m_stored ) + { + CalamaresUtils::Partition::automountRestore( m_stored ); + m_stored.reset(); + } + else + { + m_stored = CalamaresUtils::Partition::automountDisable( m_disable ); + } + return Calamares::JobResult::ok(); +} diff --git a/src/modules/partition/jobs/AutoMountManagementJob.h b/src/modules/partition/jobs/AutoMountManagementJob.h new file mode 100644 index 000000000..e1dcf16dc --- /dev/null +++ b/src/modules/partition/jobs/AutoMountManagementJob.h @@ -0,0 +1,42 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#ifndef PARTITION_AUTOMOUNTMANAGEMENTJOB_H +#define PARTITION_AUTOMOUNTMANAGEMENTJOB_H + +#include "Job.h" + +#include "partition/AutoMount.h" + +/** + * This job sets automounting to a specific value, and when run a + * second time, **re**sets to the original value. See the documentation + * for CalamaresUtils::Partition::automountDisable() for details. + * Use @c true to **disable** automounting. + * + * Effectively: queue the **same** job twice; the first time it runs + * it will set the automount behavior, and the second time it + * restores the original. + * + */ +class AutoMountManagementJob : public Calamares::Job +{ + Q_OBJECT +public: + AutoMountManagementJob( bool disable = true ); + + QString prettyName() const override; + Calamares::JobResult exec() override; + +private: + bool m_disable; + decltype( CalamaresUtils::Partition::automountDisable( true ) ) m_stored; +}; + +#endif /* PARTITION_AUTOMOUNTMANAGEMENTJOB_H */