[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 "utils/Logger.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
{
|
{
|
||||||
@ -90,24 +91,41 @@ unmount( const QString& path, const QStringList& options )
|
|||||||
return r.getExitCode();
|
return r.getExitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryMount::TemporaryMount( const QString& devicePath,
|
struct TemporaryMount::Private
|
||||||
const QString& mountPoint,
|
|
||||||
const QString& filesystemName,
|
|
||||||
const QString& options )
|
|
||||||
: m_devicePath( devicePath )
|
|
||||||
{
|
{
|
||||||
int r = mount( m_devicePath, mountPoint, filesystemName, options );
|
QString m_devicePath;
|
||||||
m_valid = r == 0;
|
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()
|
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 Partition
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
@ -60,16 +60,18 @@ class DLLEXPORT TemporaryMount
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemporaryMount( const QString& devicePath,
|
TemporaryMount( const QString& devicePath,
|
||||||
const QString& mountPoint,
|
|
||||||
const QString& filesystemName = QString(),
|
const QString& filesystemName = QString(),
|
||||||
const QString& options = QString() );
|
const QString& options = QString() );
|
||||||
|
TemporaryMount( const TemporaryMount& ) = delete;
|
||||||
|
TemporaryMount& operator=( const TemporaryMount& ) = delete;
|
||||||
~TemporaryMount();
|
~TemporaryMount();
|
||||||
|
|
||||||
bool isValid() const { return m_valid; }
|
bool isValid() const { return m_d; }
|
||||||
|
QString path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_devicePath;
|
struct Private;
|
||||||
bool m_valid;
|
Private* m_d = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Partition
|
} // namespace Partition
|
||||||
|
@ -246,13 +246,11 @@ lookForFstabEntries( const QString& partitionPath )
|
|||||||
<< "for fstab (fs=" << r.getOutput() << ')';
|
<< "for fstab (fs=" << r.getOutput() << ')';
|
||||||
|
|
||||||
FstabEntryList fstabEntries;
|
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() )
|
if ( mount.isValid() )
|
||||||
{
|
{
|
||||||
QFile fstabFile( mountsDir.path() + "/etc/fstab" );
|
QFile fstabFile( mount.path() + "/etc/fstab" );
|
||||||
|
|
||||||
cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();
|
cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user