[libcalamares] Move TemporaryDir into TemporaryMount
- Only one user of TemporaryMount, and we should distinguish "regular" temp mounts from temp mounts with a hand-picked mount point.
This commit is contained in:
parent
08537823ae
commit
d3df346ce7
@ -24,6 +24,7 @@
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user