diff --git a/src/libcalamares/partition/Mount.cpp b/src/libcalamares/partition/Mount.cpp index fa7a49c0e..12c9f0d7c 100644 --- a/src/libcalamares/partition/Mount.cpp +++ b/src/libcalamares/partition/Mount.cpp @@ -82,6 +82,24 @@ 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 ) +{ + int r = mount( m_devicePath, mountPoint, filesystemName, options ); + m_valid = r == 0; +} + +TemporaryMount::~TemporaryMount() +{ + if ( m_valid ) + { + unmount( m_devicePath ); + } +} + } // namespace Partition } // namespace CalamaresUtils diff --git a/src/libcalamares/partition/Mount.h b/src/libcalamares/partition/Mount.h index 1053d85b0..58b049093 100644 --- a/src/libcalamares/partition/Mount.h +++ b/src/libcalamares/partition/Mount.h @@ -53,6 +53,23 @@ DLLEXPORT int mount( const QString& devicePath, * @returns the program's exit codeor special codes like mount(). */ DLLEXPORT int unmount( const QString& path, const QStringList& options = QStringList() ); + +DLLEXPORT class TemporaryMount +{ +public: + TemporaryMount( const QString& devicePath, + const QString& mountPoint, + const QString& filesystemName = QString(), + const QString& options = QString() ); + ~TemporaryMount(); + + bool isValid() const { return m_valid; } + +private: + QString m_devicePath; + bool m_valid; +}; + } // namespace Partition } // namespace CalamaresUtils