From f682c3a7dd00fa62958b02907f92221f8a643b7b Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Mon, 22 Mar 2021 13:21:56 +0100 Subject: [PATCH] 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 --- downloadthread.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/downloadthread.cpp b/downloadthread.cpp index 4e51b96..1fa0e5c 100644 --- a/downloadthread.cpp +++ b/downloadthread.cpp @@ -807,6 +807,7 @@ void DownloadThread::setImageCustomization(const QByteArray &config, const QByte bool DownloadThread::_customizeImage() { QString folder; + std::vector 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;