From 1de7b55c3b2df308ddd785ae5aa8f356be61bb84 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 28 Nov 2014 15:50:27 +0100 Subject: [PATCH] ClearMountsJob: umount all partitions before making changes to a device. Fixes #169 --- src/modules/partition/CMakeLists.txt | 1 + src/modules/partition/jobs/ClearMountsJob.cpp | 74 +++++++++++++++++++ src/modules/partition/jobs/ClearMountsJob.h | 41 ++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/modules/partition/jobs/ClearMountsJob.cpp create mode 100644 src/modules/partition/jobs/ClearMountsJob.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 5a9dcd935..7ef67cb3e 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -42,6 +42,7 @@ calamares_add_plugin( partition gui/PartitionViewStep.cpp gui/PrettyRadioButton.cpp jobs/CheckFileSystemJob.cpp + jobs/ClearMountsJob.cpp jobs/CreatePartitionJob.cpp jobs/CreatePartitionTableJob.cpp jobs/DeletePartitionJob.cpp diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp new file mode 100644 index 000000000..88083037b --- /dev/null +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "ClearMountsJob.h" + +#include +#include +#include +#include +#include + +#include + + +ClearMountsJob::ClearMountsJob( Device* device ) + : Calamares::Job() + , m_device( device ) +{ +} + + +QString +ClearMountsJob::prettyName() const +{ + return tr( "Clear mounts for partitioning operations on %1" ) + .arg( m_device->deviceNode() ); +} + + +Calamares::JobResult +ClearMountsJob::exec() +{ + QStringList goodNews; + for ( auto it = PartitionIterator::begin( m_device ); + it != PartitionIterator::end( m_device ); ++it ) + { + if ( (*it)->isMounted() ) + { + if ( (*it)->canUnmount() ) + { + Report report( 0, QString() ); + (*it)->unmount( report ); + goodNews.append( report.toText() ); + } + else + { + return Calamares::JobResult::error( tr( "Cannot umount partition %1" ) + .arg( (*it)->deviceNode() ), + tr( "Cannot proceed with partitioning operations " + "because some partitions are still mounted." ) ); + } + } + } + Calamares::JobResult ok = Calamares::JobResult::ok(); + ok.setMessage( tr( "Cleared all mounts for %1" ) + .arg( m_device->deviceNode() ) ); + ok.setDetails( goodNews.join( "\n" ) ); + return ok; +} diff --git a/src/modules/partition/jobs/ClearMountsJob.h b/src/modules/partition/jobs/ClearMountsJob.h new file mode 100644 index 000000000..6a68e2811 --- /dev/null +++ b/src/modules/partition/jobs/ClearMountsJob.h @@ -0,0 +1,41 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CLEARMOUNTSJOB_H +#define CLEARMOUNTSJOB_H + +#include + +class Device; + +/** + * This job tries to free all mounts for the given device, so partitioning + * operations can proceed. + */ +class ClearMountsJob : public Calamares::Job +{ + Q_OBJECT +public: + explicit ClearMountsJob( Device* device ); + QString prettyName() const override; + Calamares::JobResult exec() override; +private: + Device* m_device; +}; + +#endif // CLEARMOUNTSJOB_H