diff --git a/src/libcalamares/partition/Mount.cpp b/src/libcalamares/partition/Mount.cpp index 8eed0ce49..08903b58c 100644 --- a/src/libcalamares/partition/Mount.cpp +++ b/src/libcalamares/partition/Mount.cpp @@ -24,6 +24,7 @@ #include "utils/Logger.h" #include +#include namespace CalamaresUtils { @@ -90,24 +91,41 @@ unmount( const QString& path, const QStringList& options ) return r.getExitCode(); } -TemporaryMount::TemporaryMount( const QString& devicePath, - const QString& mountPoint, - const QString& filesystemName, - const QString& options ) - : m_devicePath( devicePath ) +struct TemporaryMount::Private { - int r = mount( m_devicePath, mountPoint, filesystemName, options ); - m_valid = r == 0; + QString m_devicePath; + QTemporaryDir m_mountDir; +}; + + +TemporaryMount::TemporaryMount( const QString& devicePath, const QString& filesystemName, const QString& options ) + : m_d( new Private ) +{ + m_d->m_devicePath = devicePath; + m_d->m_mountDir.setAutoRemove( false ); + int r = mount( devicePath, m_d->m_mountDir.path(), filesystemName, options ); + if ( !r ) + { + delete m_d; + m_d = nullptr; + } } TemporaryMount::~TemporaryMount() { - if ( m_valid ) + if ( m_d ) { - unmount( m_devicePath, { "-R" } ); + unmount( m_d->m_devicePath, { "-R" } ); + delete m_d; + m_d = nullptr; } } +QString +TemporaryMount::path() const +{ + return m_d ? m_d->m_mountDir.path() : QString(); +} } // namespace Partition } // namespace CalamaresUtils diff --git a/src/libcalamares/partition/Mount.h b/src/libcalamares/partition/Mount.h index c8ffd0c23..0bde9b21b 100644 --- a/src/libcalamares/partition/Mount.h +++ b/src/libcalamares/partition/Mount.h @@ -60,16 +60,18 @@ class DLLEXPORT TemporaryMount { public: TemporaryMount( const QString& devicePath, - const QString& mountPoint, const QString& filesystemName = QString(), const QString& options = QString() ); + TemporaryMount( const TemporaryMount& ) = delete; + TemporaryMount& operator=( const TemporaryMount& ) = delete; ~TemporaryMount(); - bool isValid() const { return m_valid; } + bool isValid() const { return m_d; } + QString path() const; private: - QString m_devicePath; - bool m_valid; + struct Private; + Private* m_d = nullptr; }; } // namespace Partition diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index e77046b48..5443a5d74 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -246,13 +246,11 @@ lookForFstabEntries( const QString& partitionPath ) << "for fstab (fs=" << r.getOutput() << ')'; FstabEntryList fstabEntries; - QTemporaryDir mountsDir; - mountsDir.setAutoRemove( false ); - CalamaresUtils::Partition::TemporaryMount mount( partitionPath, mountsDir.path(), QString(), mountOptions.join(',') ); + CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join(',') ); if ( mount.isValid() ) { - QFile fstabFile( mountsDir.path() + "/etc/fstab" ); + QFile fstabFile( mount.path() + "/etc/fstab" ); cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();