Image customization: search all mountpoints for config.txt

Search all mountpoints associated with the target drive for
FAT partition that has config.txt

Ref: #171
This commit is contained in:
Floris Bos 2021-03-22 13:21:56 +01:00
parent 2bbb8bfba7
commit f682c3a7dd

View file

@ -807,6 +807,7 @@ void DownloadThread::setImageCustomization(const QByteArray &config, const QByte
bool DownloadThread::_customizeImage()
{
QString folder;
std::vector<std::string> mountpoints;
QByteArray devlower = _filename.toLower();
emit preparationStatusUpdate(tr("Waiting for FAT partition to be mounted"));
@ -832,14 +833,14 @@ bool DownloadThread::_customizeImage()
{
if (QByteArray::fromStdString(i.device).toLower() == devlower && i.mountpoints.size())
{
folder = QByteArray::fromStdString(i.mountpoints.front());
mountpoints = i.mountpoints;
break;
}
}
}
#ifdef Q_OS_WIN
if (folder.isEmpty() && !_nr.isEmpty()) {
if (mountpoints.empty() && !_nr.isEmpty()) {
qDebug() << "Windows did not assign drive letter automatically. Ask diskpart to do so manually.";
proc.start("diskpart");
proc.waitForStarted();
@ -855,7 +856,7 @@ bool DownloadThread::_customizeImage()
{
if (QByteArray::fromStdString(i.device).toLower() == devlower && i.mountpoints.size())
{
folder = QByteArray::fromStdString(i.mountpoints.front());
mountpoints = i.mountpoints;
break;
}
}
@ -865,7 +866,7 @@ bool DownloadThread::_customizeImage()
#ifdef Q_OS_LINUX
bool manualmount = false;
if (folder.isEmpty())
if (mountpoints.empty())
{
/* Manually mount folder */
manualmount = true;
@ -880,7 +881,7 @@ bool DownloadThread::_customizeImage()
/* Not running as root, try to outsource mounting to udisks2 */
#ifndef QT_NO_DBUS
UDisks2Api udisks2;
folder = udisks2.mountDevice(fatpartition);
mountpoints.push_back(udisks2.mountDevice(fatpartition).toStdString());
#endif
}
else
@ -888,8 +889,8 @@ bool DownloadThread::_customizeImage()
/* Running as root, attempt running mount directly */
QTemporaryDir td;
QStringList args;
folder = td.path();
args << "-t" << "vfat" << fatpartition << folder;
mountpoints.push_back(td.path().toStdString());
args << "-t" << "vfat" << fatpartition << td.path();
if (QProcess::execute("mount", args) != 0)
{
@ -901,7 +902,7 @@ bool DownloadThread::_customizeImage()
}
#endif
if (folder.isEmpty())
if (mountpoints.empty())
{
//
qDebug() << "drive info. searching for:" << devlower;
@ -921,15 +922,32 @@ bool DownloadThread::_customizeImage()
/* Some operating system take longer to complete mounting FAT32
wait up to 3 seconds for config.txt file to appear */
QString configFilename = folder+"/config.txt";
QString configFilename;
bool foundFile = false;
for (int tries = 0; tries < 3; tries++)
{
if (QFile::exists(configFilename))
/* Search all mountpoints, as on some systems FAT partition
may not be first volume */
for (auto mp : mountpoints)
{
folder = QString::fromStdString(mp);
if (!folder.isEmpty() && folder.back() == '\\')
folder.chop(1);
configFilename = folder+"/config.txt";
if (QFile::exists(configFilename))
{
foundFile = true;
break;
}
}
if (foundFile)
break;
QThread::sleep(1);
}
if (!QFile::exists(configFilename))
if (!foundFile)
{
emit error(tr("Unable to customize. File '%1' does not exist.").arg(configFilename));
return false;