[libcalamares] Add a RAII mounter
- mount on creation, unmount on destruction
This commit is contained in:
parent
2b4ffb2bd3
commit
dd0adeb3bb
@ -82,6 +82,24 @@ unmount( const QString& path, const QStringList& options )
|
|||||||
return r.getExitCode();
|
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 Partition
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
@ -53,6 +53,23 @@ DLLEXPORT int mount( const QString& devicePath,
|
|||||||
* @returns the program's exit codeor special codes like mount().
|
* @returns the program's exit codeor special codes like mount().
|
||||||
*/
|
*/
|
||||||
DLLEXPORT int unmount( const QString& path, const QStringList& options = QStringList() );
|
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 Partition
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user