[libcalamares] Add a RAII mounter

- mount on creation, unmount on destruction
This commit is contained in:
Adriaan de Groot 2019-06-20 14:34:08 +02:00
parent 2b4ffb2bd3
commit dd0adeb3bb
2 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -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